| 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 |
| 4 |
|
| 5 |
void use(int); |
| 6 |
|
| 7 |
void f() { |
| 8 |
const int a = 1; // expected-note {{here}} |
| 9 |
|
| 10 |
#if __cplusplus >= 201103L |
| 11 |
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 |
#endif |
| 18 |
|
| 19 |
struct Inner { |
| 20 |
void test(int i) { |
| 21 |
// id-expression |
| 22 |
use(a); |
| 23 |
|
| 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}} |
| 30 |
|
| 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}} |
| 37 |
|
| 38 |
// class member access naming a static data member |
| 39 |
// FIXME: How to test this? |
| 40 |
|
| 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 |
| 47 |
|
| 48 |
// parentheses |
| 49 |
use((a)); |
| 50 |
#if __cplusplus >= 201103L |
| 51 |
use((s.x)); |
| 52 |
#endif |
| 53 |
|
| 54 |
// glvalue conditional expression |
| 55 |
use(i ? a : a); |
| 56 |
use(i ? i : a); |
| 57 |
|
| 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}} |
| 63 |
|
| 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 |
| 69 |
} |
| 70 |
}; |
| 71 |
} |
| 72 |
|
| 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); |
| 80 |
} |