fun-template-def.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // Tests that dependent expressions are always allowed, whereas non-dependent
  3. // are checked as usual.
  4. #include <stddef.h>
  5. // Fake typeid, lacking a typeinfo header.
  6. namespace std { class type_info {}; }
  7. struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
  8. template<typename T>
  9. int f0(T x) {
  10. return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;
  11. }
  12. template <typename T, typename U>
  13. T f1(T t1, U u1, int i1)
  14. {
  15. T t2 = i1;
  16. t2 = i1 + u1;
  17. ++u1;
  18. u1++;
  19. int i2 = u1;
  20. i1 = t1[u1];
  21. i1 *= t1;
  22. i1(u1, t1); // error
  23. u1(i1, t1);
  24. U u2 = (T)i1;
  25. static_cast<void>(static_cast<U>(reinterpret_cast<T>(
  26. dynamic_cast<U>(const_cast<T>(i1)))));
  27. new U(i1, t1);
  28. new int(t1, u1);
  29. new (t1, u1) int;
  30. delete t1;
  31. dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}
  32. dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}
  33. dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}
  34. i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}}
  35. return u1;
  36. }
  37. template<typename T>
  38. void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}
  39. void f3() {
  40. f2<int*>(0);
  41. f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
  42. }