I'm trying to figure out whether GCC or Clang interpret the C++17 standard differently / wrong here.
This is my code, which does compile using GCC 8, but not using Clang 6:
struct BoolHolder {
constexpr static bool b = true;
};
template<bool b>
class Foo {};
int main() {
BoolHolder b;
Foo<b.b> f; // Works
BoolHolder & br = b;
Foo<br.b> f2; // Doesn't work
}
I wonder why that is. Obviously, b.b
is a valid constexpr (or the first Foo<b.b>
wouldn't be valid). Is br.b
not a valid constexpr? Why? The object or the reference itself should have nothing to do with it, since we're accessing a static constexpr member here, right?
If this is really not valid C++17, should the fact that GCC doesn't even warn me (even though I enabled -Wall -Wextra -pedantic
) be considered a bug?
constexpr int f(int) { return 0;}
, wouldf(x)
be aconstexpr
forint x;
? stackoverflow.com/questions/47696686/… – Evgbr
is not constexpr and so everything based onbr
is also not constexpr. Maybe as workaround you could useBoolHolder::b
, ifBoolHolder
is not constant within this context you might usedecltype
. – Marcel