39 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s2 3struct S {4 int *j = &nonexistent; // expected-error {{use of undeclared identifier 'nonexistent'}}5 int *m = &n; // ok6 7 int n = f(); // ok8 int f();9};10 11int i = sizeof(S::m); // ok12int j = sizeof(S::m + 42); // ok13 14 15struct T {16 int n;17 static void f() {18 int a[n]; // expected-error {{invalid use of member 'n' in static member function}}19 int b[sizeof n]; // ok20 }21};22 23// Make sure the rule for unevaluated operands works correctly with typeid.24namespace std {25 class type_info;26}27class Poly { virtual ~Poly(); };28const std::type_info& k = typeid(S::m);29const std::type_info& m = typeid(*(Poly*)S::m); // expected-error {{invalid use of non-static data member}}30const std::type_info& n = typeid(*(Poly*)(0*sizeof S::m)); 31 32namespace PR11956 {33 struct X { char a; };34 struct Y { int f() { return sizeof(X::a); } }; // ok35 36 struct A { enum E {} E; };37 struct B { int f() { return sizeof(A::E); } }; // ok38}39