g++ 4.9.0 accepts the following code:
enum E { foo };
struct C {
operator E() const { return foo; }
operator E() { return foo; }
};
int main() {
C c;
switch (c) {
case foo: break;
}
}
But clang 3.4.1 rejects it with the following diagnostic:
12 : error: multiple conversions from switch condition type 'C' to an integral or enumeration type
switch (c)
^ ~
5 : note: conversion to enumeration type 'E'
operator E() const { return foo; }
^
6 : note: conversion to enumeration type 'E'
operator E() { return foo; }
^
Which one is correct? Is it a clang bug, g++ bug, libstdc++ bug, standard defect, or other? Did I do something stupid?
In the code which triggered this question, C
is std::atomic<E>
, and std::atomic<T>::operator T
is overloaded on the cv-qualifiers const
and const volatile
.
Both compilers accept E e = c;
, so it seems to be something peculiar to the switch
statement.