Skip to content

Commit 42d9da7

Browse files
committed
[FOLD] make missing 'template' keyword an extension
1 parent 95ca24b commit 42d9da7

File tree

10 files changed

+33
-39
lines changed

10 files changed

+33
-39
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,7 @@ def missing_template_arg_list_after_template_kw : Extension<
892892
"keyword">, InGroup<DiagGroup<"missing-template-arg-list-after-template-kw">>,
893893
DefaultError;
894894

895-
def err_missing_dependent_template_keyword : Error<
896-
"use 'template' keyword to treat '%0' as a dependent template name">;
897-
def warn_missing_dependent_template_keyword : ExtWarn<
895+
def ext_missing_dependent_template_keyword : ExtWarn<
898896
"use 'template' keyword to treat '%0' as a dependent template name">;
899897

900898
def ext_extern_template : Extension<

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
566566
// member of an unknown specialization. However, this will only
567567
// parse correctly as a template, so suggest the keyword 'template'
568568
// before 'getAs' and treat this as a dependent template name.
569-
unsigned DiagID = diag::err_missing_dependent_template_keyword;
570-
if (getLangOpts().MicrosoftExt)
571-
DiagID = diag::warn_missing_dependent_template_keyword;
572-
573-
Diag(Tok.getLocation(), DiagID)
569+
Diag(Tok.getLocation(), diag::ext_missing_dependent_template_keyword)
574570
<< II.getName()
575571
<< FixItHint::CreateInsertion(Tok.getLocation(), "template ");
576572
}
@@ -2577,7 +2573,7 @@ bool Parser::ParseUnqualifiedIdTemplateId(
25772573
else
25782574
Name += Id.Identifier->getName();
25792575
}
2580-
Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword)
2576+
Diag(Id.StartLocation, diag::ext_missing_dependent_template_keyword)
25812577
<< Name
25822578
<< FixItHint::CreateInsertion(Id.StartLocation, "template ");
25832579
}

clang/test/CXX/basic/basic.lookup/basic.lookup.qual/basic.lookup.qual.general/p3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ namespace Unambiguous {
3131
t.x;
3232
t.A::x;
3333
t.B::x;
34-
t.C<int>::x; // expected-error {{use 'template' keyword to treat 'C' as a dependent template name}}
34+
t.C<int>::x; // expected-warning {{use 'template' keyword to treat 'C' as a dependent template name}}
3535
t.template C<int>::x;
36-
t.D<int>::x; // expected-error {{use 'template' keyword to treat 'D' as a dependent template name}}
36+
t.D<int>::x; // expected-warning {{use 'template' keyword to treat 'D' as a dependent template name}}
3737
t.template D<int>::x;
3838
t.E::x;
3939
}

clang/test/CXX/class.derived/class.member.lookup/p8.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ template<typename T>
4747
void DerivedT<T>::Inner() {
4848
Derived1T<T>::Foo();
4949
Derived2T<T>::Member = 42;
50-
this->Derived1T<T>::Foo(); // expected-error{{use 'template' keyword to treat 'Derived1T' as a dependent template name}}
51-
this->Derived2T<T>::Member = 42; // expected-error{{use 'template' keyword to treat 'Derived2T' as a dependent template name}}
50+
this->Derived1T<T>::Foo(); // expected-warning{{use 'template' keyword to treat 'Derived1T' as a dependent template name}}
51+
this->Derived2T<T>::Member = 42; // expected-warning{{use 'template' keyword to treat 'Derived2T' as a dependent template name}}
5252
this->Foo(); // expected-error{{non-static member 'Foo' found in multiple base-class subobjects of type 'BaseT<int>'}}
5353
}
5454

clang/test/CXX/temp/temp.res/p3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ template<typename T> int A<T>::template C<int>::*f5() {} // expected-error {{has
3030
template<typename T> template<typename U> struct A<T>::B {
3131
friend A<T>::C<T> f6(); // ok, same as 'friend T f6();'
3232

33-
friend A<U>::C<T> f7(); // expected-error {{use 'template' keyword to treat 'C' as a dependent template name}} expected-warning {{missing 'typename'}}
33+
friend A<U>::C<T> f7(); // expected-warning {{use 'template' keyword to treat 'C' as a dependent template name}} expected-warning {{missing 'typename'}}
3434
friend A<U>::template C<T> f8(); // expected-warning {{missing 'typename'}}
3535
};

clang/test/Parser/cxx2a-concepts-requires-expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool r22 = requires { typename s::~s; };
7878

7979
template<typename T>
8080
bool r23 = requires { typename identity<T>::temp<T>; };
81-
// expected-error@-1 {{use 'template' keyword to treat 'temp' as a dependent template name}}
81+
// expected-warning@-1 {{use 'template' keyword to treat 'temp' as a dependent template name}}
8282

8383
template<typename T>
8484
bool r24 = requires {

clang/test/SemaTemplate/dependent-base-classes.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
22

33
template<typename T, typename U>
4-
struct X0 : T::template apply<U> {
4+
struct X0 : T::template apply<U> {
55
X0(U u) : T::template apply<U>(u) { }
66
};
77

88
template<typename T, typename U>
9-
struct X1 : T::apply<U> { }; // expected-error{{use 'template' keyword to treat 'apply' as a dependent template name}}
9+
struct X1 : T::apply<U> { }; // expected-warning{{use 'template' keyword to treat 'apply' as a dependent template name}}
1010

1111
template<typename T>
1212
struct X2 : vector<T> { }; // expected-error{{no template named 'vector'}}
@@ -85,7 +85,7 @@ namespace PR6081 {
8585
struct A { };
8686

8787
template<typename T>
88-
class B : public A<T>
88+
class B : public A<T>
8989
{
9090
public:
9191
template< class X >
@@ -109,9 +109,9 @@ namespace PR6081 {
109109

110110
namespace PR6413 {
111111
template <typename T> class Base_A { };
112-
112+
113113
class Base_B { };
114-
114+
115115
template <typename T>
116116
class Derived
117117
: public virtual Base_A<T>
@@ -120,12 +120,12 @@ namespace PR6413 {
120120
}
121121

122122
namespace PR5812 {
123-
template <class T> struct Base {
124-
Base* p;
125-
};
123+
template <class T> struct Base {
124+
Base* p;
125+
};
126126

127-
template <class T> struct Derived: public Base<T> {
128-
typename Derived::Base* p; // meaning Derived::Base<T>
127+
template <class T> struct Derived: public Base<T> {
128+
typename Derived::Base* p; // meaning Derived::Base<T>
129129
};
130130

131131
Derived<int> di;

clang/test/SemaTemplate/dependent-template-recover.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
template<typename T, typename U, int N>
33
struct X {
44
void f(T* t) {
5-
t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
6-
t->f0<int>(); // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
5+
t->f0<U>(); // expected-warning{{use 'template' keyword to treat 'f0' as a dependent template name}}
6+
t->f0<int>(); // expected-warning{{use 'template' keyword to treat 'f0' as a dependent template name}}
77

8-
t->operator+<U const, 1>(1); // expected-error{{use 'template' keyword to treat 'operator +' as a dependent template name}}
9-
t->f1<int const, 2>(1); // expected-error{{use 'template' keyword to treat 'f1' as a dependent template name}}
8+
t->operator+<U const, 1>(1); // expected-warning{{use 'template' keyword to treat 'operator +' as a dependent template name}}
9+
t->f1<int const, 2>(1); // expected-warning{{use 'template' keyword to treat 'f1' as a dependent template name}}
1010
t->f1<3, int const>(1); // expected-error{{missing 'template' keyword prior to dependent template name 'f1'}}
1111

12-
T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
13-
t->T::getAs<U>(); // expected-error{{use 'template' keyword to treat 'getAs' as a dependent template name}}
12+
T::getAs<U>(); // expected-warning{{use 'template' keyword to treat 'getAs' as a dependent template name}}
13+
t->T::getAs<U>(); // expected-warning{{use 'template' keyword to treat 'getAs' as a dependent template name}}
1414

1515
(*t).f2<N>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}
1616
(*t).f2<0>(); // expected-error{{missing 'template' keyword prior to dependent template name 'f2'}}

clang/test/SemaTemplate/template-id-expr.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ template<typename T>
1919
struct X0 {
2020
template<typename U>
2121
void f1();
22-
22+
2323
template<typename U>
2424
void f2(U) {
2525
f1<U>();
@@ -39,9 +39,9 @@ struct Y {
3939
template<int I>
4040
struct X {
4141
X(int, int);
42-
void f() {
43-
Y<X<I> >(X<I>(0, 0));
44-
Y<X<I> >(::X<I>(0, 0));
42+
void f() {
43+
Y<X<I> >(X<I>(0, 0));
44+
Y<X<I> >(::X<I>(0, 0));
4545
}
4646
};
4747

@@ -149,11 +149,11 @@ struct Y2 : Y1<T> {
149149

150150
int x;
151151
x = Y1::f4(0);
152-
x = Y1::f4<int>(0); // expected-error {{use 'template'}} expected-error {{assigning to 'int' from incompatible type 'void'}}
152+
x = Y1::f4<int>(0); // expected-warning {{use 'template'}} expected-error {{assigning to 'int' from incompatible type 'void'}}
153153
x = Y1::template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
154154

155155
x = p->f4(0);
156-
x = p->f4<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-error {{use 'template'}}
156+
x = p->f4<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-warning {{use 'template'}}
157157
x = p->template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
158158
}
159159
};
@@ -184,7 +184,7 @@ class E {
184184
#if __cplusplus <= 199711L
185185
// expected-warning@+2 {{extension}}
186186
#endif
187-
template<typename T> using D = int; // expected-note {{declared here}}
187+
template<typename T> using D = int; // expected-note {{declared here}}
188188
E<D> ed; // expected-note {{instantiation of}}
189189

190190
namespace non_functions {

clang/test/SemaTemplate/typename-specifier-3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace PR12884_half_fixed {
4646
typedef int arg;
4747
};
4848
struct C {
49-
typedef typename B::X<typename B::arg> x; // expected-error {{use 'template'}} expected-error {{refers to non-type}}
49+
typedef typename B::X<typename B::arg> x; // expected-warning {{use 'template'}} expected-error {{refers to non-type}}
5050
};
5151
};
5252

0 commit comments

Comments
 (0)