I was working on a C++11 project solely using clang++-3.4
, and decided to compile using g++-4.8.2
in case there were any discrepancies in the errors produced. It turned out that g++ rejects some code that clang++ accepts. I have reduced the problem to the MWE given below.
enum { a };
template <class T>
struct foo
{
static constexpr auto value = a;
};
int main()
{
static constexpr auto r = foo<int>::value;
}
foo.cpp:5:23: error: ‘
const<anonymous enum> foo<int>::value
’, declared using anonymous type, is used but never defined [-fpermissive]static const auto value = A;
I would like some help answering the following two questions:
Which compiler is correct in its interpretation of the standard? I am assuming that one compiler is right in either accepting or rejecting the code, and the other is wrong.
How can I work around this issue? I can't name the anonymous enum, because it is from a third-party library (in my case, the enums were
Eigen::RowMajor
andEigen::ColMajor
).