class-template-id.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T, typename U = float> struct A { };
  3. typedef A<int> A_int;
  4. typedef float FLOAT;
  5. A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {
  6. if (ptr)
  7. return ptr; // okay
  8. else if (ptr2)
  9. return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'const A<int> *'}}
  10. else {
  11. return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'A<int, double> *'}}
  12. }
  13. }
  14. template<int I> struct B;
  15. const int value = 12;
  16. B<17 + 2> *bar(B<(19)> *ptr1, B< (::value + 7) > *ptr2, B<19 - 3> *ptr3) {
  17. if (ptr1)
  18. return ptr1;
  19. else if (ptr2)
  20. return ptr2;
  21. else
  22. return ptr3; // expected-error{{cannot initialize return object of type 'B<17 + 2> *' with an lvalue of type 'B<19 - 3>}}
  23. }
  24. typedef B<5> B5;
  25. namespace N {
  26. template<typename T> struct C {};
  27. }
  28. N::C<int> c1;
  29. typedef N::C<float> c2;
  30. // PR5655
  31. template<typename T> struct Foo { }; // expected-note{{template is declared here}}
  32. void f(void) { Foo bar; } // expected-error{{use of class template 'Foo' requires template arguments}}
  33. // rdar://problem/8254267
  34. template <typename T> class Party;
  35. template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}