Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

limits(1120): error #3377: constexpr function return is non-constant

Alex_K_8
Beginner
1,184 Views

When attempting to use the workaround for the limits(1120): error : identifier "__builtin_nanf" is undefined bug, I'm greeted by the following errors:

 0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1120): error #3377: constexpr function return is non-constant
 0:25.36                return (__builtin_nanf("0"));
 0:25.36                       ^
 0:25.36
 0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1125): error #3377: constexpr function return is non-constant
 0:25.36                return (__builtin_nansf("1"));
 0:25.36                       ^
 0:25.36
 0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1183): error #3377: constexpr function return is non-constant
 0:25.36                return (__builtin_nan("0"));
 0:25.36                       ^
 0:25.36
 0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1188): error #3377: constexpr function return is non-constant
 0:25.36                return (__builtin_nans("1"));

In the comments of the article someone mentioned using -D__builtin_nan(p)=NAN (etc) which works around for a few of the macros but not all of them:

__builtin_huge_val()=HUGE_VAL
__builtin_huge_valf()=HUGE_VALF
__builtin_nan(p)=NAN
__builtin_nanf(p)=NANF
__builtin_nans(p)=NAN
__builtin_nansf(p)=NANF

Returns:

 0:24.99 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1120): error: identifier "NANF" is undefined
 0:24.99                return (__builtin_nanf("0"));
 0:24.99                        ^
 0:24.99
 0:24.99 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1125): error: identifier "NANF" is undefined
 0:25.00                return (__builtin_nansf("1"));
 0:25.00                        ^

What's the correct way to work around this issue?

0 Kudos
9 Replies
Melanie_B_Intel
Employee
1,184 Views

The workaround documented here was tested, https://software.intel.com/en-us/articles/limits1120-error-identifier-builtin-nanf-is-undefined

Depending on what command shell you use, the parentheses may need to be quoted. For example in replies to that post, Tim said that he needed to use backslash character before the the left and right parenthesis.  Instead of using -D options, another suggestion to that post is to create a workaround file e.g. workaround.h which contains #define for the problematic builtin calls, see the suggestion from Kirill. Then use the compiler option /FI force include which causes workaround.h to be processed before every source file.  

With those macro definitions in place, there shouldn't be any calls to those builtin's in the preprocessed source. You could confirm that by running the preprocessor using the -E option and check the output to confirm that the string __builtin_nan and __builtin_huge isn't found.

e..g file limits.cpp contains

#include <limits>

icl -c -E -FI workaround.h limits.cpp > output.txt

confirm that output.txt doesn't contain the unwanted symbols

0 Kudos
Alex_K_8
Beginner
1,184 Views

Melanie Blower (Intel) wrote:

The workaround documented here was tested, https://software.intel.com/en-us/articles/limits1120-error-identifier-bu...

Depending on what command shell you use, the parentheses may need to be quoted. For example in replies to that post, Tim said that he needed to use backslash character before the the left and right parenthesis.  Instead of using -D options, another suggestion to that post is to create a workaround file e.g. workaround.h which contains #define for the problematic builtin calls, see the suggestion from Kirill. Then use the compiler option /FI force include which causes workaround.h to be processed before every source file.  

With those macro definitions in place, there shouldn't be any calls to those builtin's in the preprocessed source. You could confirm that by running the preprocessor using the -E option and check the output to confirm that the string __builtin_nan and __builtin_huge isn't found.

e..g file limits.cpp contains

#include <limits>

icl -c -E -FI workaround.h limits.cpp > output.txt

confirm that output.txt doesn't contain the unwanted symbols

Hi Melanie, I can confirm that the preprocessed source doesn't contain those builtin's, but in production code the error in the first post is being thrown.

  • Use of the compiler flag workaround brings up error #3377: constexpr function return is non-constant
  • The workaround header also produces the same error
  • Use of backslashes still returns the same error as well.

I prefer to force include the header just to keep the command line a bit less cluttered.

So to summarise, when using the workaround header as is:

#define __builtin_huge_val() HUGE_VAL
#define __builtin_huge_valf() HUGE_VALF
#define __builtin_nan nan
#define __builtin_nanf nanf
#define __builtin_nans nan
#define __builtin_nansf nanf

the following errors are thrown:

0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1120): error #3377: constexpr function return is non-constant
0:25.36                return (__builtin_nanf("0"));
0:25.36                       ^
0:25.36
0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1125): error #3377: constexpr function return is non-constant
0:25.36                return (__builtin_nansf("1"));
0:25.36                       ^
0:25.36
0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1183): error #3377: constexpr function return is non-constant
0:25.36                return (__builtin_nan("0"));
0:25.36                       ^
0:25.36
0:25.36 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1188): error #3377: constexpr function return is non-constant
0:25.36                return (__builtin_nans("1"));

With some fiddling around, I manage to get the header like this:

#define __builtin_huge_val() HUGE_VAL
#define __builtin_huge_valf() HUGE_VALF
#define __builtin_nan(p) NAN
#define __builtin_nanf(p) NANF
#define __builtin_nans(p) NAN
#define __builtin_nansf(p) NANF

Which knocks it down to these two errors:

 0:26.13 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1120): error: identifier "NANF" is undefined
 0:26.13                return (__builtin_nanf("0"));
 0:26.13                        ^
 0:26.14
 0:26.14 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1125): error: identifier "NANF" is undefined
 0:26.14                return (__builtin_nansf("1"));
 0:26.14                        ^

Which if I'm not mistaken is because NANF (uppercase) isn't defined. Ok, so if we use nanf which is defined, it just throws a error: return value type does not match the function type which I assume is because of (p). But if we remove the (p), we're back to square one again...

Neither of the __builtin_huge macros are the issue, it's the __builtin_nan macros that are causing the issues, and I have no idea why as I've tried the workarounds as well.

0 Kudos
Melanie_B_Intel
Employee
1,184 Views

Ok, with this workaround.h I can see that <limits> will compile successfully, using /FIworkaround.h

However this test case produces an error,

#include <limits>
constexpr float f = std::numeric_limits<float>::quiet_NaN();

M:\>icl -Qstd=c++11 -c limits.cpp /FIworkaround.h
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.1.146 Build 20151021
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

limits.cpp
limits.cpp(2): error: function call must have a constant value in a constant expression
  constexpr float f = std::numeric_limits<float>::quiet_NaN();
                      ^

compilation aborted for limits.cpp (code 2)

M:\>type workaround.h
#if _MSC_FULL_VER == 190023506 && __INTEL_COMPILER == 1600

#define __builtin_huge_val()  HUGE_VAL
#define __builtin_huge_valf() HUGE_VALF
#define __builtin_nan         nan
#define __builtin_nanf        nanf
#define __builtin_nans        nan
#define __builtin_nansf       nanf

#endif

Is this what you see also? 

0 Kudos
Judith_W_Intel
Employee
1,184 Views

 

I think your defines are incorrect. The bottom four should be something like:


#define __builtin_nanf(p) nanf(p)

Note the lowercase and the forwarding of the argument into the substitute routine.

The top two (the huge_val ones) look fine.

 

 

0 Kudos
Alex_K_8
Beginner
1,184 Views

In reply to your first post, the error I see is the one in the original post.

Judith Ward (Intel) wrote:

 

I think your defines are incorrect. The bottom four should be something like:

#define __builtin_nanf(p) nanf(p)

Note the lowercase and the forwarding of the argument into the substitute routine.

The top two (the huge_val ones) look fine.

 

 

Unfortunately that still returns the same error:

 6:32.41 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1120): error #3377: constexpr function return is non-constant
 6:32.41                return (__builtin_nanf("0"));
 6:32.41                       ^
 6:32.43
 6:32.43 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\limits(1125): error #3377: constexpr function return is non-constant
 6:32.43                return (__builtin_nansf("1"));
 6:32.43                       ^

 

0 Kudos
meldaproduction
Beginner
1,184 Views
Doesn't work here really.

With these:

#define __builtin_huge_val()  HUGE_VAL
#define __builtin_huge_valf() HUGE_VALF
#define __builtin_nan(p)         nan(p)
#define __builtin_nanf(p)        nanf(p)
#define __builtin_nans(p)       nan(p)
#define __builtin_nansf(p)       nanf(p)

I get this:

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1115): warning #265: floating-point operation result is out of range
                return (__builtin_huge_valf());
                        ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1120): error #3377: constexpr function return is non-constant
                return (__builtin_nanf("0"));
                       ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1125): error #3377: constexpr function return is non-constant
                return (__builtin_nansf("1"));
                       ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1178): warning #265: floating-point operation result is out of range
                return (__builtin_huge_val());
                        ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1183): error #3377: constexpr function return is non-constant
                return (__builtin_nan("0"));
                       ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1188): error #3377: constexpr function return is non-constant
                return (__builtin_nans("1"));
                       ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1241): warning #265: floating-point operation result is out of range
                return (__builtin_huge_val());
                        ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1246): error #3377: constexpr function return is non-constant
                return (__builtin_nan("0"));
                       ^

C:/Program Files (x86)\Microsoft Visual Studio 14.0\VC\include/limits(1251): error #3377: constexpr function return is non-constant
                return (__builtin_nans("1"));
                       ^

 

0 Kudos
Judith_W_Intel
Employee
1,184 Views

 

Could you please include enough information for us to reproduce the problem.

This would mean:

(1) A test case (are you just doing an #include <limits>)?

(2) The header file with the defines (or are the defines included directly in the source)?

(3) Your command line.

(4)  Your preprocessed file (i.e. use the -P option with your command line and attach the file with the extension .i that gets produced after preprocessing).

thanks

Judy

0 Kudos
David_B_10
Beginner
1,184 Views

I applied the fix described by the original poster to Visual Studio 2015 Community edition with Intel Studio Cluster edition update 2. So I now have these in the preprocessor.

__builtin_huge_val()=HUGE_VAL
__builtin_huge_valf()=HUGE_VALF
__builtin_nan=nan
__builtin_nanf=nanf
__builtin_nans=nan
__builtin_nansf=nanf

And when I build I get the following errors. 6 lines of these:. 

constexpr function return is non-constant

But if I right-click on them in the Error list tab, I can see that Show Intellisense error is ticked. If i untick that, the errors vanish. In either case (ticked or not) though they are shown as errors, the build worked perfectly and can be run.

 

 

0 Kudos
Bernard
Valued Contributor I
1,184 Views

>>>limits.cpp
limits.cpp(2): error: function call must have a constant value in a constant expression
  constexpr float f = std::numeric_limits<float>::quiet_NaN();>>>

IIRC  initialization of constexpt variable can be done only by constexpr declared function. On the other hand it is quite strange that ICC came very late with full support of constexpr funcionality.

0 Kudos
Reply