[cfe-commits] r145395 - in /cfe/trunk: lib/Parse/ParseTemplate.cpp test/FixIt/fixit.cpp

Richard Smith richard-llvm at metafoo.co.uk
Tue Nov 29 01:09:06 PST 2011


Author: rsmith
Date: Tue Nov 29 03:09:06 2011
New Revision: 145395

URL: http://llvm.org/viewvc/llvm-project?rev=145395&view=rev
Log:
Add fix-it to remove 'typedef' from function template definitions. Such a token
was probably meant to be 'typename', which we will have already suggested if it
is appropriate.

Modified:
    cfe/trunk/lib/Parse/ParseTemplate.cpp
    cfe/trunk/test/FixIt/fixit.cpp

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=145395&r1=145394&r2=145395&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Tue Nov 29 03:09:06 2011
@@ -276,9 +276,11 @@
   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);

Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=145395&r1=145394&r2=145395&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Tue Nov 29 03:09:06 2011
@@ -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 @@
 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();
+}





More information about the cfe-commits mailing list