metafun-apply.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. struct add_pointer {
  3. template<typename T>
  4. struct apply {
  5. typedef T* type;
  6. };
  7. };
  8. struct add_reference {
  9. template<typename T>
  10. struct apply {
  11. typedef T& type; // expected-error{{cannot form a reference to 'void'}}
  12. };
  13. };
  14. struct bogus {
  15. struct apply {
  16. typedef int type;
  17. };
  18. };
  19. template<typename MetaFun, typename T>
  20. struct apply1 {
  21. typedef typename MetaFun::template apply<T>::type type; // expected-note{{in instantiation of template class 'add_reference::apply<void>' requested here}} \
  22. // expected-error{{'apply' following the 'template' keyword does not refer to a template}}
  23. };
  24. int i;
  25. apply1<add_pointer, int>::type ip = &i;
  26. apply1<add_reference, int>::type ir = i;
  27. apply1<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}}
  28. void test() {
  29. apply1<add_reference, void>::type t; // expected-note{{in instantiation of template class 'apply1<add_reference, void>' requested here}}
  30. apply1<bogus, int>::type t2; // expected-note{{in instantiation of template class 'apply1<bogus, int>' requested here}}
  31. }