[PATCH] Better macro error messages involving initializer lists

Richard Trieu rtrieu at google.com
Fri Jul 19 17:40:16 PDT 2013


  Also fixed a problem where the too many arguments error was always pointing to the last argument.  It now properly points to the first extra element.


================
Comment at: lib/Lex/PPMacroExpansion.cpp:443
@@ +442,3 @@
+  unsigned Braces = 0;
+  unsigned Parens = 0;
+
----------------
Richard Smith wrote:
> This variable seems to be unused.
Variable removed.

================
Comment at: lib/Lex/PPMacroExpansion.cpp:482
@@ +481,3 @@
+
+        // If the argument starts with a brace, 
+        if (FoundSeparatorToken && ArgStartIterator->is(tok::l_brace)) {
----------------
Richard Smith wrote:
> Incomplete comment.
Done.

================
Comment at: lib/Lex/PPMacroExpansion.cpp:693-696
@@ +692,6 @@
+                 diag::note_init_list_at_beginning_of_macro_argument);
+        for (SmallVector<SourceRange, 4>::iterator
+                 Range = InitLists.begin(), RangeEnd = InitLists.end();
+                 Range != RangeEnd; ++Range)
+          DB << *Range; 
+      }
----------------
Richard Smith wrote:
> It looks like DiagnosticBuilder will assert if given more than 10 ranges. Maybe guard this with DB.hasMaxRanges()?
Done with test case.

================
Comment at: lib/Lex/PPMacroExpansion.cpp:704-709
@@ +703,8 @@
+    DiagnosticBuilder DB = Diag(MacroName, diag::note_suggest_parens_for_macro);
+    for (SmallVector<SourceRange, 4>::iterator
+             ParenLocation = ParenHints.begin(), ParenEnd = ParenHints.end();
+         ParenLocation != ParenEnd; ++ParenLocation) {
+      DB << FixItHint::CreateInsertion(ParenLocation->getBegin(), "(")
+         << FixItHint::CreateInsertion(ParenLocation->getEnd(), ")");
+    }
+    ArgTokens.swap(FixedArgTokens);
----------------
Richard Smith wrote:
> Likewise w/fixits.
Done with test case.

================
Comment at: test/Preprocessor/macro_with_initializer_list.cpp:140
@@ +139,3 @@
+// make it no longer an initializer list.
+// TODO: Add note for initializer list at beginning of macro argument.
+void test() {
----------------
Richard Smith wrote:
> This is done, right?
Yes.


http://llvm-reviews.chandlerc.com/D986



More information about the cfe-commits mailing list