p2.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. // C++11 [class.mem]p2:
  3. // A class is considered a completely-defined object type (or
  4. // complete type) at the closing } of the class-specifier. Within
  5. // the class member-specification, the class is regarded as complete
  6. // within function bodies, default arguments,
  7. // exception-specifications, and brace-or-equal-initializers for
  8. // non-static data members (including such things in nested classes).
  9. // Otherwise it is regarded as incomplete within its own class
  10. // member-specification.
  11. namespace test0 {
  12. struct A { // expected-note {{definition of 'test0::A' is not complete until the closing '}'}}
  13. A x; // expected-error {{field has incomplete type 'test0::A'}}
  14. };
  15. }
  16. namespace test1 {
  17. template <class T> struct A {
  18. A<int> x; // expected-error {{implicit instantiation of template 'test1::A<int>' within its own definition}}
  19. };
  20. }
  21. namespace test2 {
  22. template <class T> struct A;
  23. template <> struct A<int> {};
  24. template <class T> struct A {
  25. A<int> x;
  26. };
  27. }
  28. namespace test3 {
  29. struct A {
  30. struct B {
  31. void f() throw(A);
  32. void g() throw(B);
  33. };
  34. void f() throw(A);
  35. void g() throw(B);
  36. };
  37. template<typename T>
  38. struct A2 {
  39. struct B {
  40. void f1() throw(A2);
  41. void f2() throw(A2<T>);
  42. void g() throw(B);
  43. };
  44. void f1() throw(A2);
  45. void f2() throw(A2<T>);
  46. void g() throw(B);
  47. };
  48. template struct A2<int>;
  49. }
  50. namespace PR12629 {
  51. struct S {
  52. static int (f)() throw();
  53. static int ((((((g))))() throw(U)));
  54. int (*h)() noexcept(false);
  55. static int (&i)() noexcept(true);
  56. static int (*j)() throw(U); // expected-error {{unknown type name 'U'}}
  57. static int (k)() throw(U);
  58. struct U {};
  59. };
  60. static_assert(noexcept(S::f()), "");
  61. static_assert(!noexcept(S::g()), "");
  62. static_assert(!noexcept(S().h()), "");
  63. static_assert(noexcept(S::i()), "");
  64. }
  65. namespace PR12688 {
  66. struct S {
  67. // FIXME: Maybe suppress the "constructor cannot have a return type" error
  68. // if the return type is invalid.
  69. nonsense S() throw (more_nonsense); // \
  70. // expected-error {{'nonsense'}} \
  71. // expected-error {{constructor cannot have a return type}}
  72. };
  73. }