The following code is not compiled in gcc 4.8.1 through 6.3:
#include <cassert>
template<typename T, T X>
struct Mode {
using type = Mode;
using value_type = T;
static constexpr value_type value = X;
^^^ error: 'constexpr const value_type Mode<main()::TestEnum, (main::TestEnum)0>::value', declared using local type 'const value_type {aka const main()::TestEnum}', is used but never defined [-fpermissive]
constexpr operator value_type() const noexcept { return value; }
};
int main()
{
enum class TestEnum { test1, test2 };
constexpr Mode<TestEnum, TestEnum::test1> test1 = {};
constexpr Mode<TestEnum, TestEnum::test2> test2 = {};
assert(static_cast<TestEnum>(test1) == TestEnum::test1);
}
clang 3.9.1 and MSVC 2015 SP3 compile it without errors.
If I move enum class TestEnum { test1, test2 };to a global scope, then it compiles without errors.
Is the code legal? or am i doing something wrong?
source
share