-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
static constexpr class members are required to have a definition #788
Comments
I don't see any error with clang 5.0: https://godbolt.org/g/DrbUZe |
The problem is not at compile time but at link time, you can see it if you click on 11010 in godbolt:
|
No, it wouldn't, e.g. struct Foo {
static constexpr auto i = 42;
};
template <typename T>
void f(T&& i) {}
int main() {
f(Foo::i);
} gives
According to [basic.def.odr]:
This requirement was relaxed in C++17, so your example should compile there. On C++14 and earlier you should provide an out-of-class definition of your variable. |
In fact with c++17, it fails both with g++ 8.1.0 and clang 6.0.0 with a much less easy to understand message. |
That's because Compiler Explorer doesn't link with the fmt library. Your example compiles when using header-only mode: https://godbolt.org/g/DhyUfd |
OK, thanks, I did not know that godbolt could not link with libraries. |
The following program does not compile with clang++ 5.0.2. With g++ 7.3.0, it does not compile in debug mode but compiles with -O2. The error is that the class static constexpr int i is required to have an address because fmt::format takes its arguments by const reference. However I do not understand why g++ work in release mode! Would it be possible that fmt::format takes its arguments by universal references &&? Would that improve this situation?
The text was updated successfully, but these errors were encountered: