cxx-templates.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // RUN: rm -rf %t
  2. // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL
  3. // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter N | FileCheck %s --check-prefix=CHECK-NAMESPACE-N
  4. // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
  5. @import cxx_templates_a;
  6. @import cxx_templates_b;
  7. template<typename, char> struct Tmpl_T_C {};
  8. template<typename, int, int> struct Tmpl_T_I_I {};
  9. template<typename A, typename B, A> struct Tmpl_T_T_A {};
  10. template<typename A, typename B, B> struct Tmpl_T_T_B {};
  11. void g() {
  12. f(0);
  13. f<double>(1.0);
  14. f<int>();
  15. f(); // expected-error {{no matching function}}
  16. // expected-note@Inputs/cxx-templates-b.h:3 {{couldn't infer template argument}}
  17. // expected-note@Inputs/cxx-templates-b.h:4 {{requires single argument}}
  18. N::f(0);
  19. N::f<double>(1.0);
  20. N::f<int>();
  21. N::f(); // expected-error {{no matching function}}
  22. // expected-note@Inputs/cxx-templates-a.h:6 {{couldn't infer template argument}}
  23. // expected-note@Inputs/cxx-templates-a.h:7 {{requires 1 argument, but 0 were provided}}
  24. template_param_kinds_1<0>(); // ok, from cxx-templates-a.h
  25. template_param_kinds_1<int>(); // ok, from cxx-templates-b.h
  26. template_param_kinds_2<Tmpl_T_C>(); // expected-error {{no matching function}}
  27. // expected-note@Inputs/cxx-templates-a.h:11 {{invalid explicitly-specified argument}}
  28. // expected-note@Inputs/cxx-templates-b.h:11 {{invalid explicitly-specified argument}}
  29. template_param_kinds_2<Tmpl_T_I_I>(); // expected-error {{ambiguous}}
  30. // expected-note@Inputs/cxx-templates-a.h:11 {{candidate}}
  31. // expected-note@Inputs/cxx-templates-b.h:11 {{candidate}}
  32. // FIXME: This should be valid, but we incorrectly match the template template
  33. // argument against both template template parameters.
  34. template_param_kinds_3<Tmpl_T_T_A>(); // expected-error {{ambiguous}}
  35. // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
  36. // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
  37. template_param_kinds_3<Tmpl_T_T_B>(); // expected-error {{ambiguous}}
  38. // expected-note@Inputs/cxx-templates-a.h:12 {{candidate}}
  39. // expected-note@Inputs/cxx-templates-b.h:12 {{candidate}}
  40. }
  41. @import cxx_templates_common;
  42. typedef SomeTemplate<int*> SomeTemplateIntPtr;
  43. typedef SomeTemplate<int&> SomeTemplateIntRef;
  44. SomeTemplate<char*> some_template_char_ptr;
  45. SomeTemplate<char&> some_template_char_ref;
  46. // FIXME: There should only be two 'f's here.
  47. // CHECK-GLOBAL: DeclarationName 'f'
  48. // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
  49. // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
  50. // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
  51. // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
  52. // FIXME: There should only be two 'f's here.
  53. // CHECK-NAMESPACE-N: DeclarationName 'f'
  54. // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
  55. // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
  56. // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
  57. // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'