]> granicus.if.org Git - clang/commitdiff
Add fix-it to remove 'typedef' from function template definitions. Such a token
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 29 Nov 2011 09:09:06 +0000 (09:09 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 29 Nov 2011 09:09:06 +0000 (09:09 +0000)
was probably meant to be 'typename', which we will have already suggested if it
is appropriate.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145395 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseTemplate.cpp
test/FixIt/fixit.cpp

index 91cf8e81c2a48bff5ae1418af4aab8ebbf481d78..7b09f8191d2d9916678f9eecc8979653b82fd756 100644 (file)
@@ -276,9 +276,11 @@ Parser::ParseSingleDeclarationAfterTemplate(
   if (DeclaratorInfo.isFunctionDeclarator() &&
       isStartOfFunctionDefinition(DeclaratorInfo)) {
     if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
-      Diag(Tok, diag::err_function_declared_typedef);
-
-      // Recover by ignoring the 'typedef'.
+      // Recover by ignoring the 'typedef'. This was probably supposed to be
+      // the 'typename' keyword, which we should have already suggested adding
+      // if it's appropriate.
+      Diag(DS.getStorageClassSpecLoc(), diag::err_function_declared_typedef)
+        << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
       DS.ClearStorageClassSpecs();
     }
     return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo);
index 7c8ba9ac6f1a353931c293c2f5a388cc9f915609..e0fa6088c371fb09dbb2c51c6c71b7d5aab8f314 100644 (file)
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -pedantic -Wall -verify -fcxx-exceptions -x c++ %s
+// RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s
 // RUN: cp %s %t
-// RUN: not %clang_cc1 -pedantic -Wall -fcxx-exceptions -fixit -x c++ %t
-// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -fcxx-exceptions -x c++ %t
+// RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ %t
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ %t
 
 /* This is a test of the various code modification hints that are
    provided as part of warning or extension diagnostics. All of the
@@ -135,3 +135,10 @@ int extraSemi2(); // expected-error {{stray ';' in function definition}}
 try {
 } catch (...) {
 }
+
+template<class T> struct Mystery;
+template<class T> typedef Mystery<T>::type getMysteriousThing() { // \
+  expected-error {{function definition declared 'typedef'}} \
+  expected-error {{missing 'typename' prior to dependent}}
+  return Mystery<T>::get();
+}