Consider the following code, which compiles fine in clang but not in gcc (4.7.2):
template<typename T> using remove_ref_typed =
typename std::remove_reference<T>::type; // alias-template w/ 'typename'
template<typename T> using remove_ref =
std::remove_reference<T>; // alias-template w/o 'typename'
enum class E : int { E0, E1 }; // some enum class
class C {} obj; // some non-enum class
void proof_of_concept()
{
remove_ref<C&>::type o1 = obj; // ... gcc ok
remove_ref_typed<C&> o2 = obj; // ... gcc ok
remove_ref<E&>::type e1 = E::E1; // ... gcc ok
remove_ref_typed<E&> e2 = E::E1; // ... gcc internal "bus error"
}
The code compiles fine in clang, but in gcc (4.7.2) the final statement results in:
sandbox_cpp11.cpp:100:22: internal compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
The difference between the problematic statement and the previous 3 statements is:
- It involves an enum class type, instead of non-enum class type.
- It uses an alias-template which declares
typename
and::type
for convenience
My question: Does use of typename
in this way (in an "alias template") comply with the C++11 standard even if used in a context in which the typename
specifier wouldn't otherwise be necessary? Or is this a "language non-compliance bug" in gcc?