cxx11-templates.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
  2. struct S {
  3. template <typename Ty = char>
  4. static_assert(sizeof(Ty) != 1, "Not a char"); // expected-error {{a static_assert declaration cannot be a template}}
  5. };
  6. template <typename Ty = char>
  7. static_assert(sizeof(Ty) != 1, "Not a char"); // expected-error {{a static_assert declaration cannot be a template}}
  8. namespace Ellipsis {
  9. template<typename ...T> void f(T t..., int n); // expected-error {{must immediately precede declared identifier}}
  10. template<typename ...T> void f(int n, T t...); // expected-error {{must immediately precede declared identifier}}
  11. template<typename ...T> void f(int n, T t, ...); // expected-error {{unexpanded parameter pack}}
  12. template<typename ...T> void f() {
  13. f([]{
  14. void g(T
  15. t // expected-note {{place '...' immediately before declared identifier to declare a function parameter pack}}
  16. ... // expected-warning {{'...' in this location creates a C-style varargs function, not a function parameter pack}}
  17. // expected-note@-1 {{insert ',' before '...' to silence this warning}}
  18. );
  19. void h(T (&
  20. ) // expected-note {{place '...' here to declare a function parameter pack}}
  21. ... // expected-warning {{'...' in this location creates a C-style varargs function, not a function parameter pack}}
  22. // expected-note@-1 {{insert ',' before '...' to silence this warning}}
  23. );
  24. void i(T (&), ...);
  25. }...);
  26. }
  27. template<typename ...T> struct S {
  28. void f(T t...); // expected-error {{must immediately precede declared identifier}}
  29. void f(T ... // expected-note {{preceding '...' declares a function parameter pack}}
  30. t...); // expected-warning-re {{'...' in this location creates a C-style varargs function{{$}}}}
  31. // expected-note@-1 {{insert ',' before '...' to silence this warning}}
  32. };
  33. // FIXME: We should just issue a single error in this case pointing out where
  34. // the '...' goes. It's tricky to recover correctly in this case, though,
  35. // because the parameter is in scope in the default argument, so must be
  36. // passed to Sema before we reach the ellipsis.
  37. template<typename...T> void f(T n = 1 ...);
  38. // expected-warning@-1 {{creates a C-style varargs}}
  39. // expected-note@-2 {{place '...' immediately before declared identifier}}
  40. // expected-note@-3 {{insert ','}}
  41. // expected-error@-4 {{unexpanded parameter pack}}
  42. }