[cfe-dev] std::enable_if<T::a> with enum T::a = 2

Ansgar Burchardt ansgar.burchardt at iwr.uni-heidelberg.de
Thu Sep 13 07:31:04 PDT 2012


Hi,

I'm not sure if this is the right list, but I encountered a problem with
std::enable_if in clang++:

---
#include <iostream>
#include <type_traits>

template<int n>
struct A {
  enum { a = n };
};

template<class T, typename dummy = void>
struct B
{
  enum { b = 1 };
};

template<class T>
struct B<T, typename std::enable_if<T::a>::type>
{
  enum { b = 2 };
};

int main(void)
{
  std::cout << B< A<1> >::b << std::endl;
  std::cout << B< A<2> >::b << std::endl;
}
---

This will give "2 1" with clang 3.1-8 (Debian), but "2 2" with g++
4.7.1-8 (Debian).  I'm far from being an expert in C++, but shouldn't
both lines use the specialized version of B (ie. g++ is correct)?

I do get the expected result if I use

    std::enable_if<(T::a, true)>::type

instead.

Ansgar

PS: Please CC my on replies. I'm not subscribed to the list.



More information about the cfe-dev mailing list