blob: 5da00837cc09e1485df5ba8a907bea9e9cd4ed65 [file] [log] [blame]
Francois Pichet00c7e6c2011-08-14 03:52:19 +00001// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
Richard Smith07cea192013-04-29 08:53:40 +00002// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s
Francois Pichet00c7e6c2011-08-14 03:52:19 +00003
Francois Pichet00c7e6c2011-08-14 03:52:19 +00004class A {
5public:
Richard Smith3c9198f2013-12-13 22:26:20 +00006 template<class U> A(U p) {}
7 template<> A(int p) {
8 // expected-warning@-1 {{explicit specialization of 'A' within class scope is a Microsoft extension}}
9 }
Francois Pichet00c7e6c2011-08-14 03:52:19 +000010
Richard Smith3c9198f2013-12-13 22:26:20 +000011 template<class U> void f(U p) {}
Francois Pichet00c7e6c2011-08-14 03:52:19 +000012
Richard Smith3c9198f2013-12-13 22:26:20 +000013 template<> void f(int p) {
14 // expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
15 }
16
17 void f(int p) {}
Francois Pichet00c7e6c2011-08-14 03:52:19 +000018};
19
Richard Smith3c9198f2013-12-13 22:26:20 +000020void test1() {
21 A a(3);
22 char *b;
23 a.f(b);
24 a.f<int>(99);
25 a.f(100);
Francois Pichet00c7e6c2011-08-14 03:52:19 +000026}
27
Richard Smith3c9198f2013-12-13 22:26:20 +000028template<class T> class B {
Francois Pichet00c7e6c2011-08-14 03:52:19 +000029public:
Richard Smith3c9198f2013-12-13 22:26:20 +000030 template<class U> B(U p) {}
31 template<> B(int p) {
32 // expected-warning@-1 {{explicit specialization of 'B<T>' within class scope is a Microsoft extension}}
33 }
Francois Pichet00c7e6c2011-08-14 03:52:19 +000034
Richard Smith3c9198f2013-12-13 22:26:20 +000035 template<class U> void f(U p) { T y = 9; }
Francois Pichet00c7e6c2011-08-14 03:52:19 +000036
Richard Smith3c9198f2013-12-13 22:26:20 +000037 template<> void f(int p) {
38 // expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
39 T a = 3;
40 }
Francois Pichet00c7e6c2011-08-14 03:52:19 +000041
Richard Smith3c9198f2013-12-13 22:26:20 +000042 void f(int p) { T a = 3; }
Francois Pichet00c7e6c2011-08-14 03:52:19 +000043};
44
Richard Smith3c9198f2013-12-13 22:26:20 +000045void test2() {
46 B<char> b(3);
47 char *ptr;
48 b.f(ptr);
49 b.f<int>(99);
50 b.f(100);
Francois Pichet00c7e6c2011-08-14 03:52:19 +000051}
52
Nico Weber7b5a7162012-06-25 17:21:05 +000053namespace PR12709 {
Richard Smith6cda8ee2013-12-13 22:28:48 +000054 template<class T> class TemplateClass {
55 void member_function() { specialized_member_template<false>(); }
Nico Weber7b5a7162012-06-25 17:21:05 +000056
Richard Smith6cda8ee2013-12-13 22:28:48 +000057 template<bool b> void specialized_member_template() {}
Richard Smith3c9198f2013-12-13 22:26:20 +000058
Richard Smith6cda8ee2013-12-13 22:28:48 +000059 template<> void specialized_member_template<false>() {
60 // expected-warning@-1 {{explicit specialization of 'specialized_member_template' within class scope is a Microsoft extension}}
61 }
62 };
Richard Smith3c9198f2013-12-13 22:26:20 +000063
Richard Smith6cda8ee2013-12-13 22:28:48 +000064 void f() { TemplateClass<int> t; }
65}
Nico Weber7b5a7162012-06-25 17:21:05 +000066
Richard Smith6cda8ee2013-12-13 22:28:48 +000067namespace Duplicates {
68 template<typename T> struct A {
69 template<typename U> void f();
70 template<> void f<int>() {} // expected-warning {{Microsoft extension}}
71 template<> void f<T>() {} // expected-warning {{Microsoft extension}}
72 };
73
74 // FIXME: We should diagnose the duplicate explicit specialization definitions
75 // here.
76 template struct A<int>;
Nico Weber7b5a7162012-06-25 17:21:05 +000077}