81 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -Wno-unused -verify2// RUN: %clang_cc1 -std=c++11 %s -Wno-unused -verify3// RUN: %clang_cc1 -std=c++2a %s -Wno-unused -verify4 5void use(int);6 7void f() {8 const int a = 1; // expected-note {{here}}9 10#if __cplusplus >= 201103L11 constexpr int arr[3] = {1, 2, 3}; // expected-note 2{{here}}12 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#endif18 19 struct Inner {20 void test(int i) {21 // id-expression22 use(a);23 24#if __cplusplus >= 201103L25 // subscripting operation with an array operand26 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}}30 31 // class member access naming non-static data member32 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}}37 38 // class member access naming a static data member39 // FIXME: How to test this?40 41 // pointer-to-member expression42 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#endif47 48 // parentheses49 use((a));50#if __cplusplus >= 201103L51 use((s.x));52#endif53 54 // glvalue conditional expression55 use(i ? a : a);56 use(i ? i : a);57 58 // comma expression59 use((i, a));60 // FIXME: This is not an odr-use because it is a discarded-value61 // expression applied to an expression whose potential result is 'a'.62 use((a, a)); // expected-error {{reference to local variable}}63 64 // (and combinations thereof)65 use(a ? (i, a) : a);66#if __cplusplus >= 201103L67 use(a ? (i, a) : arr[a ? s.x : arr[a]]);68#endif69 }70 };71}72 73// FIXME: Test that this behaves properly.74namespace 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);80}81