p2.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
  2. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  3. struct X0 {
  4. X0 f1();
  5. X0 f2();
  6. };
  7. template<typename T>
  8. struct X1 {
  9. X1<T>(int);
  10. (X1<T>)(float);
  11. X1 f2();
  12. X1 f2(int);
  13. X1 f2(float);
  14. };
  15. // Error recovery: out-of-line constructors whose names have template arguments.
  16. template<typename T> X1<T>::X1<T>(int) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
  17. template<typename T> (X1<T>::X1<T>)(float) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
  18. // Error recovery: out-of-line constructor names intended to be types
  19. X0::X0 X0::f1() { return X0(); } // expected-error{{qualified reference to 'X0' is a constructor name rather than a type wherever a constructor can be declared}}
  20. struct X0::X0 X0::f2() { return X0(); }
  21. template<typename T> X1<T>::X1<T> X1<T>::f2() { } // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name wherever a constructor can be declared}}
  22. template<typename T> X1<T>::X1<T> (X1<T>::f2)(int) { } // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name wherever a constructor can be declared}}
  23. template<typename T> struct X1<T>::X1<T> (X1<T>::f2)(float) { }
  24. // We have a special case for lookup within using-declarations that are
  25. // member-declarations: foo::bar::baz::baz always names baz's constructor
  26. // in such a context, even if looking up 'baz' within foo::bar::baz would
  27. // not find the injected-class-name. Likewise foo::bar::baz<T>::baz also
  28. // names the constructor.
  29. namespace InhCtor {
  30. struct A {
  31. A(int);
  32. protected:
  33. int T();
  34. };
  35. typedef A T;
  36. struct B : A {
  37. // This is a using-declaration for 'int A::T()' in C++98, but is an
  38. // inheriting constructor declaration in C++11.
  39. using InhCtor::T::T;
  40. };
  41. #if __cplusplus < 201103L
  42. B b(123); // expected-error {{no matching constructor}}
  43. // expected-note@-7 2{{candidate constructor}}
  44. int n = b.T(); // ok, accessible
  45. #else
  46. B b(123); // ok, inheriting constructor
  47. int n = b.T(); // expected-error {{'T' is a protected member of 'InhCtor::A'}}
  48. // expected-note@-15 {{declared protected here}}
  49. template<typename T>
  50. struct S : T {
  51. struct U : S {
  52. using S::S;
  53. };
  54. using T::T;
  55. };
  56. S<A>::U ua(0);
  57. S<B>::U ub(0);
  58. template<typename T>
  59. struct X : T {
  60. using T::Z::U::U;
  61. };
  62. template<typename T>
  63. struct X2 : T {
  64. using T::Z::template V<int>::V;
  65. };
  66. struct Y {
  67. struct Z {
  68. typedef Y U;
  69. template<typename T> using V = Y;
  70. };
  71. Y(int);
  72. };
  73. X<Y> xy(0);
  74. namespace Repeat {
  75. struct A {
  76. struct T {
  77. T(int);
  78. };
  79. };
  80. struct Z : A {
  81. using A::A::A;
  82. };
  83. template<typename T>
  84. struct ZT : T::T {
  85. using T::T::T;
  86. };
  87. }
  88. namespace NS {
  89. struct NS {};
  90. }
  91. struct DerivedFromNS : NS::NS {
  92. // No special case unless the NNS names a class.
  93. using InhCtor::NS::NS; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}}
  94. };
  95. // FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts
  96. typedef int I;
  97. struct UsingInt {
  98. using I::I; // expected-error {{'I' (aka 'int') is not a class, namespace, or enumeration}}
  99. };
  100. template<typename T> struct UsingIntTemplate {
  101. using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
  102. };
  103. UsingIntTemplate<int> uit; // expected-note {{here}}
  104. #endif
  105. }