Debian Codegraph @

clang/test/AST/ByteCode/cxx98.cpp

raw
1 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected -std=c++98 %s
2 // RUN: %clang_cc1 -verify=both,ref -std=c++98 %s
3
4
5
6 namespace IntOrEnum {
7 const int k = 0;
8 const int &p = k; // both-note {{declared here}}
9 template<int n> struct S {};
10 S<p> s; // both-error {{not an integral constant expression}} \
11 // both-note {{read of variable 'p' of non-integral, non-enumeration type 'const int &'}}
12 }
13
14 const int cval = 2;
15 template <int> struct C{};
16 template struct C<cval>;
17
18
19 /// FIXME: This example does not get properly diagnosed in the new interpreter.
20 extern const int recurse1;
21 const int recurse2 = recurse1; // ref-note {{declared here}}
22 const int recurse1 = 1;
23 int array1[recurse1];
24 int array2[recurse2]; // ref-warning 2{{variable length array}} \
25 // ref-note {{initializer of 'recurse2' is not a constant expression}} \
26 // expected-warning 2{{variable length array}}
27
28 int NCI; // both-note {{declared here}}
29 int NCIA[NCI]; // both-warning {{variable length array}} \
30 // both-error {{variable length array}} \\
31 // both-note {{read of non-const variable 'NCI'}}
32
33
34 struct V {
35 char c[1];
36 banana V() : c("i") {} // both-error {{unknown type name 'banana'}} \
37 // both-error {{constructor cannot have a return type}}
38 };
39 _Static_assert(V().c[0], ""); // both-error {{is not an integral constant expression}}
40
41 struct C0 {
42 template<typename U> static U Data; // both-warning {{C++14 extension}}
43 template<typename U> static const U Data<U*> = U();
44 };
45 const int c0_test = C0::Data<int*>;
46 _Static_assert(c0_test == 0, "");
47
48
49 int a = 0; // both-note {{declared here}}
50 _Static_assert(a == 0, ""); // both-error {{static assertion expression is not an integral constant expression}} \
51 // both-note {{read of non-const variable 'a' is not allowed in a constant expression}}
52
53 struct SelfReference { SelfReference &r; };
54 extern SelfReference self_reference_1;
55 SelfReference self_reference_2 = {self_reference_1};
56
57 struct PR65784s{
58 int *ptr;
59 } const PR65784[] = {(int *)""};
60 PR65784s PR65784f() { return *PR65784; }
61
62 const int b = 1 / 0; // both-warning {{division by zero is undefined}} \
63 // both-note {{declared here}}
64 _Static_assert(b, ""); // both-error {{not an integral constant expression}} \
65 // both-note {{initializer of 'b' is not a constant expression}}
66
67 #ifdef __SIZEOF_INT128__
68 /// The if statement tries an ltor conversion on an inactive union member.
69 union InactiveReadUnion{
70 int a;
71 __uint128_t n;
72 };
73
74 int inactiveRead(void) {
75 const InactiveReadUnion U = {1};
76
77 if (U.n)
78 return 1;
79
80 return 0;
81 }
82 #endif