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