Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7683 Discussions

Most math functions are not considered constexpr

milian
Beginner
669 Views

Hey there!

With g++ from GCC 4.8 (and probably before that as well), I can do something like:

constexpr double foo = std::floor(4.0);

With icpc 14.0 though I get this error message:

/home/milian/projects/foo.cpp(5): error: function call must have a constant value in a constant expression
constexpr double foo = std::floor(4.0);

cmath defines std::floor with _GLIBCXX_CONSTEXPR, which is set in c++config.h:

#if __cplusplus

// Macro for constexpr, to support in mixed 03/0x mode.
#ifndef _GLIBCXX_CONSTEXPR
# if __cplusplus >= 201103L
# define _GLIBCXX_CONSTEXPR constexpr

0 Kudos
2 Replies
Judith_W_Intel
Employee
669 Views

 

I have reproduced this problem with this small test case below. I have entered this in our internal bug tracking database as DPD200249275. Thank you for bringing this to our attention.

Judy

namespace std
{
  inline constexpr float floor(float __x) {
    return __builtin_floor(__x);
  }

}

constexpr double floor = std::floor(4.0);

milian
Beginner
669 Views

Note that e.g. also happens for std::sqrt which has a more convoluted signature in mathcalls.h. Still, in GCC I can use it in an constexpr.

Reply