[cfe-dev] Compile errors when building kde-runtime

Nikola Smiljanic popizdeh at gmail.com
Tue May 22 12:48:05 PDT 2012


How about something like this? It's missing tests and stuff but I hope it's
in the right direction. Comments appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120522/c91b6bde/attachment.html>
-------------- next part --------------
Index: include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- include/clang/Basic/DiagnosticParseKinds.td	(revision 157207)
+++ include/clang/Basic/DiagnosticParseKinds.td	(working copy)
@@ -402,6 +402,10 @@
 def warn_parens_disambiguated_as_function_decl : Warning<
   "parentheses were disambiguated as a function declarator">,
   InGroup<VexingParse>;
+def note_replace_parens_for_variable_declaration : Note<
+  "replace parentheses with an initializer to declare a variable">;
+def note_additional_parens_for_variable_declaration : Note<
+  "add a pair of parentheses to declare a variable">;
 def warn_dangling_else : Warning<
   "add explicit braces to avoid dangling else">,
   InGroup<DanglingElse>;
Index: lib/Parse/ParseTentative.cpp
===================================================================
--- lib/Parse/ParseTentative.cpp	(revision 157207)
+++ lib/Parse/ParseTentative.cpp	(working copy)
@@ -1315,6 +1315,16 @@
     if (warnIfAmbiguous)
       Diag(Tok, diag::warn_parens_disambiguated_as_function_decl)
         << SourceRange(Tok.getLocation(), TPLoc);
+
+    if (getLangOpts().CPlusPlus0x)
+      Diag(Tok, diag::note_replace_parens_for_variable_declaration)
+        << FixItHint::CreateReplacement(SourceRange(Tok.getLocation()), "{")
+        << FixItHint::CreateReplacement(SourceRange(TPLoc), "}");
+    else
+      Diag(Tok, diag::note_additional_parens_for_variable_declaration)
+        << FixItHint::CreateInsertion(Tok.getLocation(), "(")
+        << FixItHint::CreateInsertion(TPLoc, ")");
+ 
     return true;
   }
 


More information about the cfe-dev mailing list