xref: /llvm-project/clang/test/SemaCXX/builtin-classify-type.cpp (revision a79a5611bd18baab02ea6ad31f7b6b767f4028a7)
1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -fexperimental-new-constant-interpreter
3 
4 // expected-no-diagnostics
5 
6 enum gcc_type_class {
7   no_type_class = -1,
8   void_type_class, integer_type_class, char_type_class,
9   enumeral_type_class, boolean_type_class,
10   pointer_type_class, reference_type_class, offset_type_class,
11   real_type_class, complex_type_class,
12   function_type_class, method_type_class,
13   record_type_class, union_type_class,
14   array_type_class, string_type_class,
15   lang_type_class, opaque_type_class,
16   bitint_type_class, vector_type_class
17 };
18 
19 class cl {
20 public:
bar()21     void bar() {}
22     int baz;
23 };
24 
25 int builtin_result;
26 
foo()27 void foo() {
28   int i;
29   char c;
30   enum { red, green, blue} enum_obj;
31   bool b;
32   int *p;
33   int &r = i;
34   double d;
35   extern void f();
36   cl cl_obj;
37   union { int a; float b; } u_obj;
38   int arr[10];
39   int (^block)();
40   __attribute__((vector_size(16))) int vec;
41   typedef __attribute__((ext_vector_type(4))) int evec_t;
42   evec_t evec;
43   _Atomic int atomic_i;
44   _Atomic double atomic_d;
45   _Complex int complex_i;
46   _Complex double complex_d;
47   _BitInt(32) bitint;
48 
49   int a1[__builtin_classify_type(f()) == void_type_class ? 1 : -1];
50   int a2[__builtin_classify_type(i) == integer_type_class ? 1 : -1];
51   int a3[__builtin_classify_type(c) == integer_type_class ? 1 : -1];
52   int a4[__builtin_classify_type(enum_obj) == enumeral_type_class ? 1 : -1];
53   int a5[__builtin_classify_type(b) == boolean_type_class ? 1 : -1];
54   int a6[__builtin_classify_type(p) == pointer_type_class ? 1 : -1];
55   int a7[__builtin_classify_type(r) == integer_type_class ? 1 : -1];
56   int a8[__builtin_classify_type(&cl::baz) == offset_type_class ? 1 : -1];
57   int a9[__builtin_classify_type(d) == real_type_class ? 1 : -1];
58   int a10[__builtin_classify_type(f) == pointer_type_class ? 1 : -1];
59   int a11[__builtin_classify_type(&cl::bar) == record_type_class ? 1 : -1];
60   int a12[__builtin_classify_type(cl_obj) == record_type_class ? 1 : -1];
61   int a13[__builtin_classify_type(u_obj) == union_type_class ? 1 : -1];
62   int a14[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
63   int a15[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
64   int a16[__builtin_classify_type(block) == no_type_class ? 1 : -1];
65   int a17[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
66   int a18[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
67   int a19[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
68   int a20[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
69   int a21[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
70   int a22[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
71   int a23[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
72 }
73 
74