1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 3 template <typename T, typename U = void*> 4 struct A { 5 enum { 6 id = _Generic(T(), // expected-error {{controlling expression type 'char' not compatible with any generic association type}} 7 int: 1, // expected-note {{compatible type 'int' specified here}} 8 float: 2, 9 U: 3) // expected-error {{type 'int' in generic association compatible with previously specified type 'int'}} 10 }; 11 }; 12 13 static_assert(A<int>::id == 1, "fail"); 14 static_assert(A<float>::id == 2, "fail"); 15 static_assert(A<double, double>::id == 3, "fail"); 16 17 A<char> a1; // expected-note {{in instantiation of template class 'A<char>' requested here}} 18 A<short, int> a2; // expected-note {{in instantiation of template class 'A<short, int>' requested here}} 19 20 template <typename T, typename U> 21 struct B { 22 enum { 23 id = _Generic(T(), 24 int: 1, // expected-note {{compatible type 'int' specified here}} 25 int: 2, // expected-error {{type 'int' in generic association compatible with previously specified type 'int'}} 26 U: 3) 27 }; 28 }; 29 30 template <unsigned Arg, unsigned... Args> struct Or { 31 enum { result = Arg | Or<Args...>::result }; 32 }; 33 34 template <unsigned Arg> struct Or<Arg> { 35 enum { result = Arg }; 36 }; 37 38 template <class... Args> struct TypeMask { 39 enum { 40 result = Or<_Generic(Args(), int: 1, long: 2, short: 4, float: 8)...>::result 41 }; 42 }; 43 44 static_assert(TypeMask<int, long, short>::result == 7, "fail"); 45 static_assert(TypeMask<float, short>::result == 12, "fail"); 46 static_assert(TypeMask<int, float, float>::result == 9, "fail"); 47