>g++ -std=c++17 main2.cpp -o main2
main2.cpp: In function 'constexpr char func(char)':
main2.cpp:5:28: error: 'ch' is not a constant expression
if constexpr (ch >= 'A')
>g++ --version
g++ (GCC) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Is my compiler just too old, or am I doing illicit things?
Edit: Please note the actual logic in the code is contrived, it's not doing anything useful.
If I make it be "constexpr char ch" I get the error
main2.cpp:3:36: error: a parameter cannot be declared 'constexpr'
constexpr char func(constexpr char ch)
What I'm trying to do is to get some char-related calculations to be calculated at compile-time, for fun, preferably without having to use template-metaprogramming.
So basically, the "constexpr if" inside the function was stricter than constexpr signature of the function. (I thought that restriction was alleviated in C++17, guess not.)
Thanks, I'll use the ternary operator for now.
Edit: And yeah, I understand that constexpr doesn't mean "has to be evaluated at compile time". Using templates or switch statements should enforce that, because case statements have to be known at compile-time, right?
And does that mean that "constexpr if" has to be a compile-time constant, being stricter than constexpr functions?