Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / basic / basic.def.odr / p2.cpp
blob0ffd08c924fbb4366c2e5b6cc1a20d4e1c6aaed5
1 // RUN: %clang_cc1 -std=c++98 %s -Wno-unused -verify
2 // RUN: %clang_cc1 -std=c++11 %s -Wno-unused -verify
3 // RUN: %clang_cc1 -std=c++2a %s -Wno-unused -verify
5 void use(int);
7 void f() {
8 const int a = 1; // expected-note {{here}}
10 #if __cplusplus >= 201103L
11 constexpr int arr[3] = {1, 2, 3}; // expected-note 2{{here}}
13 struct S { int x; int f() const; };
14 constexpr S s = {0}; // expected-note 3{{here}}
15 constexpr S *ps = nullptr;
16 S *const &psr = ps; // expected-note 2{{here}}
17 #endif
19 struct Inner {
20 void test(int i) {
21 // id-expression
22 use(a);
24 #if __cplusplus >= 201103L
25 // subscripting operation with an array operand
26 use(arr[i]);
27 use(i[arr]);
28 use((+arr)[i]); // expected-error {{reference to local variable}}
29 use(i[+arr]); // expected-error {{reference to local variable}}
31 // class member access naming non-static data member
32 use(s.x);
33 use(s.f()); // expected-error {{reference to local variable}}
34 use((&s)->x); // expected-error {{reference to local variable}}
35 use(ps->x); // ok (lvalue-to-rvalue conversion applied to id-expression)
36 use(psr->x); // expected-error {{reference to local variable}}
38 // class member access naming a static data member
39 // FIXME: How to test this?
41 // pointer-to-member expression
42 use(s.*&S::x);
43 use((s.*&S::f)()); // expected-error {{reference to local variable}}
44 use(ps->*&S::x); // ok (lvalue-to-rvalue conversion applied to id-expression)
45 use(psr->*&S::x); // expected-error {{reference to local variable}}
46 #endif
48 // parentheses
49 use((a));
50 #if __cplusplus >= 201103L
51 use((s.x));
52 #endif
54 // glvalue conditional expression
55 use(i ? a : a);
56 use(i ? i : a);
58 // comma expression
59 use((i, a));
60 // FIXME: This is not an odr-use because it is a discarded-value
61 // expression applied to an expression whose potential result is 'a'.
62 use((a, a)); // expected-error {{reference to local variable}}
64 // (and combinations thereof)
65 use(a ? (i, a) : a);
66 #if __cplusplus >= 201103L
67 use(a ? (i, a) : arr[a ? s.x : arr[a]]);
68 #endif
73 // FIXME: Test that this behaves properly.
74 namespace std_example {
75 struct S { static const int x = 0, y = 0; };
76 const int &f(const int &r);
77 bool b;
78 int n = b ? (1, S::x)
79 : f(S::y);