I want to confirm that this code is legal (or not legal?) C++17.
#include <iostream>
template<int N> inline constexpr float MyConst;
template<> inline constexpr float MyConst<1> = 1.1f;
template<> inline constexpr float MyConst<2> = 2.2f;
int main ()
{
std::cout << MyConst<1> << '\n';
return 0;
}
I don't get errors (and get correct output) if compiled by g++ and MSVC,
but Intel and clang give an error:
test.cpp(3): error: missing initializer for constexpr variable
template<int N> inline constexpr float MyConst;
^
Compiled with -std=c++17 (/std:c++17 for MSVC).
Tried with latest compilers on godbolt as well as on my local machine.