8

Trying to respond to another question, I've written the following code that behave different in g++ (6.3.0) and in clang++ (3.8.1)

#include <iostream>
#include <type_traits>

template <typename>
struct foo
 { };

template <typename T>
using alias = foo<T>;

template <template <typename...> class, template <typename...> class>
struct bar : public std::false_type
 { };

template <template <typename...> class C>
struct bar<C, C> : public std::true_type
 { };

int main()
 {
   // g++     print 1
   // clang++ print 0
   std::cout << bar<foo, alias>::value << std::endl;
 }

g++ prints 1 (that is: activate the specialization bar struct, that is treat foo and alias as equals) and clang++ prints 0 (that is: activate the generic bar struct, that is treat foo and alias as differents).

The question, as usual, is: who's right? g++ or clang++ ?

max66
  • 65,235
  • 10
  • 71
  • 111

0 Answers0