instantiate-init.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct X0 { // expected-note 8{{candidate}}
  3. X0(int*, float*); // expected-note 4{{candidate}}
  4. };
  5. template<typename T, typename U>
  6. X0 f0(T t, U u) {
  7. X0 x0(t, u); // expected-error{{no matching}}
  8. return X0(t, u); // expected-error{{no matching}}
  9. }
  10. void test_f0(int *ip, float *fp, double *dp) {
  11. f0(ip, fp);
  12. f0(ip, dp); // expected-note{{instantiation}}
  13. }
  14. template<typename Ret, typename T, typename U>
  15. Ret f1(Ret *retty, T t, U u) {
  16. Ret r0(t, u); // expected-error{{no matching}}
  17. return Ret(t, u); // expected-error{{no matching}}
  18. }
  19. void test_f1(X0 *x0, int *ip, float *fp, double *dp) {
  20. f1(x0, ip, fp);
  21. f1(x0, ip, dp); // expected-note{{instantiation}}
  22. }
  23. namespace PR6457 {
  24. template <typename T> struct X { explicit X(T* p = 0) { }; };
  25. template <typename T> struct Y { Y(int, const T& x); };
  26. struct A { };
  27. template <typename T>
  28. struct B {
  29. B() : y(0, X<A>()) { }
  30. Y<X<A> > y;
  31. };
  32. B<int> b;
  33. }
  34. namespace PR6657 {
  35. struct X
  36. {
  37. X (int, int) { }
  38. };
  39. template <typename>
  40. void f0()
  41. {
  42. X x = X(0, 0);
  43. }
  44. void f1()
  45. {
  46. f0<int>();
  47. }
  48. }
  49. // Instantiate out-of-line definitions of static data members which complete
  50. // types through an initializer even when the only use of the member that would
  51. // cause instantiation is in an unevaluated context, but one requiring its
  52. // complete type.
  53. namespace PR10001 {
  54. template <typename T> struct S {
  55. static const int arr[];
  56. static const int x;
  57. static int f();
  58. };
  59. template <typename T> const int S<T>::arr[] = { 1, 2, 3 };
  60. template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]);
  61. template <typename T> int S<T>::f() { return x; }
  62. int x = S<int>::f();
  63. }
  64. namespace PR7985 {
  65. template<int N> struct integral_c { };
  66. template <typename T, int N>
  67. integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: could not match 'T [N]' against 'const Data<}}
  68. template<typename T>
  69. struct Data {
  70. T x;
  71. };
  72. template<typename T>
  73. struct Description {
  74. static const Data<T> data[];
  75. };
  76. template<typename T>
  77. const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}}
  78. template<>
  79. const Data<float*> Description<float*>::data[];
  80. void test() {
  81. integral_c<1> ic1 = array_lengthof(Description<int>::data);
  82. (void)sizeof(array_lengthof(Description<float>::data));
  83. sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
  84. Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
  85. ));
  86. array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}}
  87. }
  88. }
  89. namespace PR13064 {
  90. // Ensure that in-class direct-initialization is instantiated as
  91. // direct-initialization and likewise copy-initialization is instantiated as
  92. // copy-initialization.
  93. struct A { explicit A(int); }; // expected-note{{here}}
  94. template<typename T> struct B { T a { 0 }; };
  95. B<A> b;
  96. // expected-note@+1 {{in instantiation of default member initializer}}
  97. template<typename T> struct C { T a = { 0 }; }; // expected-error{{explicit}}
  98. C<A> c; // expected-note{{here}}
  99. }
  100. namespace PR16903 {
  101. // Make sure we properly instantiate list-initialization.
  102. template<typename T>
  103. void fun (T it) {
  104. int m = 0;
  105. for (int i = 0; i < 4; ++i, ++it){
  106. m |= long{char{*it}};
  107. }
  108. }
  109. int test() {
  110. char in[4] = {0,0,0,0};
  111. fun(in);
  112. }
  113. }
  114. namespace ReturnStmtIsInitialization {
  115. struct X {
  116. X() {}
  117. X(const X &) = delete;
  118. };
  119. template<typename T> X f() { return {}; }
  120. auto &&x = f<void>();
  121. }