Most math functions are not considered constexpr

Most math functions are not considered constexpr

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

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

 

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);

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.

Leave a Comment

Please sign in to add a comment. Not a member? Join today