p12-0x.cpp 982 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct S {
  3. int *j = &nonexistent; // expected-error {{use of undeclared identifier 'nonexistent'}}
  4. int *m = &n; // ok
  5. int n = f(); // ok
  6. int f();
  7. };
  8. int i = sizeof(S::m); // ok
  9. int j = sizeof(S::m + 42); // ok
  10. struct T {
  11. int n;
  12. static void f() {
  13. int a[n]; // expected-error {{invalid use of member 'n' in static member function}}
  14. int b[sizeof n]; // ok
  15. }
  16. };
  17. // Make sure the rule for unevaluated operands works correctly with typeid.
  18. namespace std {
  19. class type_info;
  20. }
  21. class Poly { virtual ~Poly(); };
  22. const std::type_info& k = typeid(S::m);
  23. const std::type_info& m = typeid(*(Poly*)S::m); // expected-error {{invalid use of non-static data member}}
  24. const std::type_info& n = typeid(*(Poly*)(0*sizeof S::m));
  25. namespace PR11956 {
  26. struct X { char a; };
  27. struct Y { int f() { return sizeof(X::a); } }; // ok
  28. struct A { enum E {} E; };
  29. struct B { int f() { return sizeof(A::E); } }; // ok
  30. }