cxx-member-initializers.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct x {
  3. x() : a(4) ; // expected-error {{expected '{'}}
  4. };
  5. struct y {
  6. int a;
  7. y() : a(4) ; // expected-error {{expected '{'}}
  8. };
  9. struct z {
  10. int a;
  11. z() : a {}
  12. }; // expected-error {{expected '{'}}
  13. namespace PR16480 {
  14. template<int n> struct X {
  15. X();
  16. X(int);
  17. };
  18. struct A : X<0> {
  19. A() : X<a<b>{0}.n>() {}
  20. template<int> struct a {
  21. int n;
  22. };
  23. static const int b = 1;
  24. };
  25. struct B : X<0> {
  26. B() : X<a<b>{0} {}
  27. static const int a = 0, b = 0;
  28. };
  29. template<int> struct a {
  30. constexpr a(int) {}
  31. constexpr operator int() const { return 0; }
  32. };
  33. struct C : X<0> {
  34. C() : X<a<b>(0)>() {}
  35. static const int b = 0;
  36. };
  37. struct D : X<0> {
  38. D() : X<a<b>(0) {}
  39. static const int a = 0, b = 0;
  40. };
  41. template<typename T> struct E : X<0> {
  42. E(X<0>) : X<(0)>{} {}
  43. E(X<1>) : X<int{}>{} {}
  44. E(X<2>) : X<(0)>() {}
  45. E(X<3>) : X<int{}>() {}
  46. };
  47. // FIXME: This should be valid in the union of C99 and C++11.
  48. struct F : X<0> {
  49. F() : X<A<T>().n + (T){}.n>{} {} // expected-error +{{}}
  50. struct T { int n; };
  51. template<typename> struct A { int n; };
  52. };
  53. // FIXME: This is valid now, but may be made ill-formed by DR1607.
  54. struct G : X<0> {
  55. G() : X<0 && [](){return 0;}()>{} // expected-error +{{}}
  56. };
  57. struct Errs : X<0> {
  58. Errs(X<0>) : decltype X<0>() {} // expected-error {{expected '(' after 'decltype'}}
  59. Errs(X<1>) : what is this () {} // expected-error {{expected '(' or '{'}}
  60. Errs(X<2>) : decltype(X<0> // expected-note {{to match this '('}}
  61. }; // expected-error {{expected ')'}}
  62. }
  63. template <class U, class V> struct C {
  64. int f() { return 4; }
  65. class C1 {};
  66. };
  67. class D {};
  68. namespace N {
  69. struct E {
  70. class F {};
  71. };
  72. }
  73. class G {
  74. // These are all valid:
  75. void f(int x = C<int, D>().f()) {}
  76. void g(int x = C<int, ::D>().f()) {}
  77. void h(int x = C<int, N::E>().f()) {}
  78. void i(int x = C<int, ::N::E>().f()) {}
  79. void j(int x = C<int, decltype(N::E())::F>().f()) {}
  80. void k(int x = C<int, C<int, int>>().f()) {}
  81. void l(int x = C<int, C<int, int>::C1>().f()) {}
  82. // This isn't, but it shouldn't crash. The diagnostics don't matter much.
  83. void m(int x = C<int, union int>().f()) {} // expected-error {{declaration of anonymous union must be a definition}} expected-error {{expected a type}}
  84. };