Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit a823545

Browse files
committed
Improve & simplify diagnostic for missing 'class' in template template parameter.
Change suggested by Sebastian Redl on review feedback from r153887. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154102 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b98b998 commit a823545

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

include/clang/Basic/DiagnosticParseKinds.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ def err_unknown_template_name : Error<
479479
"unknown template name %0">;
480480
def err_expected_comma_greater : Error<
481481
"expected ',' or '>' in template-parameter-list">;
482-
def err_expected_class_before : Error<"expected 'class' before '%0'">;
483-
def err_expected_class_instead : Error<"expected 'class' instead of '%0'">;
482+
def err_expected_class_on_template_template_param : Error<
483+
"template template parameters require 'class' after the argument list">;
484484
def err_template_spec_syntax_non_template : Error<
485485
"identifier followed by '<' indicates a class template specialization but "
486486
"%0 %select{does not refer to a template|refers to a function "

lib/Parse/ParseTemplate.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,12 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
541541
// Generate a meaningful error if the user forgot to put class before the
542542
// identifier, comma, or greater.
543543
if (Tok.is(tok::kw_typename) || Tok.is(tok::kw_struct)) {
544-
Diag(Tok.getLocation(), diag::err_expected_class_instead)
545-
<< PP.getSpelling(Tok)
544+
Diag(Tok.getLocation(), diag::err_expected_class_on_template_template_param)
546545
<< FixItHint::CreateReplacement(Tok.getLocation(), "class");
547546
ConsumeToken();
548547
} else if (!Tok.is(tok::kw_class))
549-
Diag(Tok.getLocation(), diag::err_expected_class_before)
550-
<< PP.getSpelling(Tok)
551-
<< FixItHint::CreateInsertion(Tok.getLocation(), "class ");
548+
Diag(Tok.getLocation(), diag::err_expected_class_on_template_template_param)
549+
<< FixItHint::CreateInsertion(Tok.getLocation(), "class ");
552550
else
553551
ConsumeToken();
554552

test/FixIt/fixit.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ template<class T> typedef Mystery<T>::type getMysteriousThing() { // \
200200
return Mystery<T>::get();
201201
}
202202

203-
template<template<typename> Foo, // expected-error {{expected 'class' before 'Foo'}}
204-
template<typename> typename Bar, // expected-error {{expected 'class' instead of 'typename'}}
205-
template<typename> struct Baz> // expected-error {{expected 'class' instead of 'struct'}}
203+
template<template<typename> Foo, // expected-error {{template template parameters require 'class' after the argument list}}
204+
template<typename> typename Bar, // expected-error {{template template parameters require 'class' after the argument list}}
205+
template<typename> struct Baz> // expected-error {{template template parameters require 'class' after the argument list}}
206206
void func();

test/Parser/cxx-template-decl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ template < ; // expected-error {{parse error}} \
1111
// expected-warning {{declaration does not declare anything}}
1212
template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \
1313
// expected-error{{extraneous}}
14-
template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}}
15-
template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}}
14+
template <template <typename> > struct Err2; // expected-error {{template template parameters require 'class' after the argument list}}
15+
template <template <typename> Foo> struct Err3; // expected-error {{template template parameters require 'class' after the argument list}}
1616

1717
// Template function declarations
1818
template <typename T> void foo();

0 commit comments

Comments
 (0)