blob: c0a5d89fff67545f1097978d9323d2b7aec83df1 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
Peter Collingbournef111d932011-04-15 00:35:48 +00002
3template <typename T, typename U = void*>
4struct 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
13static_assert(A<int>::id == 1, "fail");
14static_assert(A<float>::id == 2, "fail");
15static_assert(A<double, double>::id == 3, "fail");
16
17A<char> a1; // expected-note {{in instantiation of template class 'A<char, void *>' requested here}}
18A<short, int> a2; // expected-note {{in instantiation of template class 'A<short, int>' requested here}}
19
20template <typename T, typename U>
21struct 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
30template <unsigned Arg, unsigned... Args> struct Or {
31 enum { result = Arg | Or<Args...>::result };
32};
33
34template <unsigned Arg> struct Or<Arg> {
35 enum { result = Arg };
36};
37
38template <class... Args> struct TypeMask {
39 enum {
40 result = Or<_Generic(Args(), int: 1, long: 2, short: 4, float: 8)...>::result
41 };
42};
43
44static_assert(TypeMask<int, long, short>::result == 7, "fail");
45static_assert(TypeMask<float, short>::result == 12, "fail");
46static_assert(TypeMask<int, float, float>::result == 9, "fail");