(non-standard?) constexpr standard library functions

I can't really find good information related to where the standard library uses constexpr functions.

To my surprise, something like this compiled, even though due to the enums it must be calculating value at compile time, right?

1
2
3
4
5
6
7
8
#include <cmath>
enum class Foo : int {
    value = static_cast<int>(std::pow(3.3, 3.3))
};
#include <iostream>
int main() {
  std::cout << static_cast<int>(Foo::value) << std::endl;
}


The same applies to other functions I tested in <cmath>.
But when I check the reference page http://www.cplusplus.com/reference/cmath/pow/ I see nothing about if it's defined as constexpr or not.

So how do I know whether a function in the standard library is constexpr? Even if I look through the header files, is this behavior standard or implementation specific?

__________________________________
Edit: After more searching, I found an answer http://stackoverflow.com/questions/27744079/is-it-a-conforming-compiler-extension-to-treat-non-constexpr-standard-library-fu
So apparently it's not allowed, but GCC appears to allow it anyway...? Correct me if I misunderstand.

So is there a way to undo the GCC extension to make it conform to standard?
Last edited on
So how do I know whether a function in the standard library is constexpr?
I suggest to look into standard for that.

So is there a way to undo the GCC extension to make it conform to standard?
Apparently you cannot yet. Even with gnu extension disabled and -pedantic-errors flag set it is still not reported as error. Best way is to just not do that. And search GCC bug tracker for this bug and read discussion.
Yep, will do. I'll just avoid it for now.
> So how do I know whether a function in the standard library is constexpr?

One would expect cppreference.com to have accurate and up to date information. For instance:
http://en.cppreference.com/w/cpp/utility/pair/make_pair

Compile (all) your code with more than one compiler; even if one misses out on conformance, another may not.

1
2
3
4
5
6
7
8
9
10
11
#include <cmath>

enum class Foo : int {
    value = static_cast<int>(std::pow(3.3, 3.3))
};

#include <iostream>

int main() {
  std::cout << static_cast<int>(Foo::value) << std::endl;
}


clang++: error: enumerator value is not a constant expression

http://coliru.stacked-crooked.com/a/62be86ca92b39876

msc++: error C2057: expected constant expression

http://rextester.com/RGJXP20848
Topic archived. No new replies allowed.