Community
cancel
Showing results for 
Search instead for 
Did you mean: 
245 Views

constant value in a constant expression

The following fails with icc but compiles fine with gcc 4.8. Any idea?

>cat foo.cc
#include <cmath>
constexpr float A_1 = std::pow (1.0,2.0);
>icpc -v
icpc version 15.0.0 (gcc version 4.8.1 compatibility)
>icpc -c -std=c++11 foo.cc
foo.cc(2): error: function call must have a constant value in a constant expression
  constexpr float A_1 = std::pow (1.0,2.0);
                        ^

compilation aborted for foo.cc (code 2)


 

0 Kudos
5 Replies
245 Views

Also this does not compile with icc too

>cat foo.cc
template <typename T>
void Func1()
{
  constexpr T zero(0);
  constexpr T nzero(-zero);
}

int Func2()
{
  constexpr float x(0);
  constexpr float nx(-x);
  Func1<float>();
}
>icpc -c -std=c++11 foo.cc
foo.cc(5): error: expression must have a constant value
    constexpr T nzero(-zero);
                       ^

compilation aborted for foo.cc (code 2)

 

Georg_Z_Intel
Employee
245 Views

Hello

we've a ticket open for this one since May (DPD200256916). The request has been forwarded to the compiler frontend team. We're waiting for an implementation. I've asked for the current status and let you know once I learn more.

Edit: I've not found a reasonable workaround for this (for CMS). Just to compile it I had to remove "constexpr" (e.g. via "#define constexpr").

Best regards,

Georg Zitzlsberger

Georg_Z_Intel
Employee
245 Views

Hello,

just a status note: DPD200256916 was different and hence I've created DPD200568523 for this.

Engineers are currently trying to fix both for 16.0 BETA (update). I'll update this thread once a sound solution is available.

Best regards,

Georg Zitzlsberger

Georg_Z_Intel
Employee
245 Views

Hello,

both examples have been analyzed now.

  • The case with "constexpr T nzero(-zero);" (DPD200568523) is a bug in 15.0. We've fixed that for 16.0 (which is currently available as BETA* version)
  • The case with "constexpr float A_1 = std::pow (1.0,2.0);" (DPD200256916) is not a bug and quite controversial (e.g. https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/a7D2SYqUX-I). We won't be able to imitate the out-of-spec behavior of GCC here, which means: Built-in math functions won't be treated as a constexpr. They still require execution at runtime. This is also required to do any FP signaling (NaN). This won't happen with GCC, which can be an issue.

Hence my proposal is:

Please try the latest 16.0 BETA compiler and avoid combining (built-in) math functions with constexpr. Rather define ordinary const values at runtime in a controlled (FP) environment to check for signals and then refer to such initialized const values.

*: To get the latest BETA version, please follow the processes described here:
https://software.intel.com/en-us/articles/intel-parallel-studio-xe-2016-beta#enrollment

Please let me know via the usual channels how this works out. We can also discuss further details.

Best regards,

Georg Zitzlsberger

Sajja__Udaya
Beginner
245 Views

Hi,

I am a newbie here. Compiling Pybind11 with Intel compilers is resulting in some compilation errors, whereas the code compiles with gcc.

pybind11/pybind11.h(167): error : a variable declared with an auto type specifier cannot appear in its own initializer 
            static constexpr auto signature = _("(") + cast_in::arg_names + _(") -> ") + cast_out::name;

detected during:
              instantiation of "void pybind11::cpp_function::initialize(Func &&, Return (*)(Args...), const Extra &...) 
              instantiation of "pybind11::cpp_function::cpp_function(Return (Class::*)(Arg...), const Extra &...) 

Is this issue related to the topic here? If so, is there any workaround for this? I am using Intel 2018 Update4 on Windows 10. 

There is an old discussion probably related to this at the following links:

https://github.com/pybind/pybind11/issues/276

https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/a7D2SYqUX-I

I appreciate any help in resolving this.

Thanks,

Udaya

 

Reply