ms-function-specialization-class-scope.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s
  3. class A {
  4. public:
  5. template<class U> A(U p) {}
  6. template<> A(int p) {
  7. // expected-warning@-1 {{explicit specialization of 'A' within class scope is a Microsoft extension}}
  8. }
  9. template<class U> void f(U p) {}
  10. template<> void f(int p) {
  11. // expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
  12. }
  13. void f(int p) {}
  14. };
  15. void test1() {
  16. A a(3);
  17. char *b;
  18. a.f(b);
  19. a.f<int>(99);
  20. a.f(100);
  21. }
  22. template<class T> class B {
  23. public:
  24. template<class U> B(U p) {}
  25. template<> B(int p) {
  26. // expected-warning@-1 {{explicit specialization of 'B<T>' within class scope is a Microsoft extension}}
  27. }
  28. template<class U> void f(U p) { T y = 9; }
  29. template<> void f(int p) {
  30. // expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
  31. T a = 3;
  32. }
  33. void f(int p) { T a = 3; }
  34. };
  35. void test2() {
  36. B<char> b(3);
  37. char *ptr;
  38. b.f(ptr);
  39. b.f<int>(99);
  40. b.f(100);
  41. }
  42. namespace PR12709 {
  43. template<class T> class TemplateClass {
  44. void member_function() { specialized_member_template<false>(); }
  45. template<bool b> void specialized_member_template() {}
  46. template<> void specialized_member_template<false>() {
  47. // expected-warning@-1 {{explicit specialization of 'specialized_member_template' within class scope is a Microsoft extension}}
  48. }
  49. };
  50. void f() { TemplateClass<int> t; }
  51. }
  52. namespace Duplicates {
  53. template<typename T> struct A {
  54. template<typename U> void f();
  55. template<> void f<int>() {} // expected-warning {{Microsoft extension}}
  56. template<> void f<T>() {} // expected-warning {{Microsoft extension}}
  57. };
  58. // FIXME: We should diagnose the duplicate explicit specialization definitions
  59. // here.
  60. template struct A<int>;
  61. }