summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseTemplate.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2012-04-02 19:15:28 +0000
committerDavid Blaikie <dblaikie@gmail.com>2012-04-02 19:15:28 +0000
commitf221e51d2a35fd50ac327fac5b0a9e649578d992 (patch)
tree692112607dcb17bc0da7ce11cd979ab33376d681 /clang/lib/Parse/ParseTemplate.cpp
parent7591afa235ecceb9c8edb7d02bc6ab6f5708acf3 (diff)
downloadbcm5719-llvm-f221e51d2a35fd50ac327fac5b0a9e649578d992.tar.gz
bcm5719-llvm-f221e51d2a35fd50ac327fac5b0a9e649578d992.zip
Correct error recovery when missing 'class' in a template template parameter.
The diagnostic message correctly informs the user that they have omitted the 'class' keyword, but neither suggests this insertion as a fixit, nor attempts to recover as if they had provided the keyword. This fixes the recovery, adds the fixit, and adds a separate diagnostic and corresponding replacement fixit for cases where the user wrote 'struct' or 'typename' instead of 'class' (suggested by Richard Smith as a possible common mistake). I'm not sure the diagnostic message for either the original or new cases feel very Clang-esque, so I'm open to suggestions there. The fixit hints make it fairly easy to see what's required, though. llvm-svn: 153887
Diffstat (limited to 'clang/lib/Parse/ParseTemplate.cpp')
-rw-r--r--clang/lib/Parse/ParseTemplate.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index 305f07bc90e..474519381e7 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -540,12 +540,17 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
// Generate a meaningful error if the user forgot to put class before the
// identifier, comma, or greater.
- if (!Tok.is(tok::kw_class)) {
- Diag(Tok.getLocation(), diag::err_expected_class_before)
- << PP.getSpelling(Tok);
- return 0;
- }
- ConsumeToken();
+ if (Tok.is(tok::kw_typename) || Tok.is(tok::kw_struct)) {
+ Diag(Tok.getLocation(), diag::err_expected_class_instead)
+ << PP.getSpelling(Tok)
+ << FixItHint::CreateReplacement(Tok.getLocation(), "class");
+ ConsumeToken();
+ } else if (!Tok.is(tok::kw_class))
+ Diag(Tok.getLocation(), diag::err_expected_class_before)
+ << PP.getSpelling(Tok)
+ << FixItHint::CreateInsertion(Tok.getLocation(), "class ");
+ else
+ ConsumeToken();
// Parse the ellipsis, if given.
SourceLocation EllipsisLoc;
OpenPOWER on IntegriCloud