]> granicus.if.org Git - clang/commitdiff
Add an assert to catch improperly constructed %diff sequences in
authorChandler Carruth <chandlerc@gmail.com>
Fri, 23 Dec 2016 05:19:47 +0000 (05:19 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 23 Dec 2016 05:19:47 +0000 (05:19 +0000)
diagnostics and fix one such diagnostic.

Sadly, this assert doesn't catch this bug because we have no tests that
emit this diagnostic! Doh! I'm following up on the commit that
introduces it to get that fixed. Then this assert will help in a more
direct way.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Basic/Diagnostic.cpp

index a95792458799a27d5e866308c093fbd0b552b4ec..3b43a6474fb67c61fa38c7717ec6cb980edbf59a 100644 (file)
@@ -3346,7 +3346,7 @@ def note_ovl_candidate_inconsistent_deduction : Note<
 def note_ovl_candidate_inconsistent_deduction_types : Note<
     "candidate template ignored: deduced values %diff{"
     "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
-    "%1 and %3 of conflicting types for parameter %0|}2,4">;
+    "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
     "candidate template ignored: invalid explicitly-specified argument "
     "for template parameter %0">;
index 1f4316af3ffbc89806f4e07a8c88cdf63c9456fe..7529c475d6b917877349f7d08ed03669a6ffea1d 100644 (file)
@@ -742,7 +742,10 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
         //   "%diff{compare $ to $|other text}1,2"
         // treat it as:
         //   "compare %1 to %2"
-        const char *Pipe = ScanFormat(Argument, Argument + ArgumentLen, '|');
+        const char *ArgumentEnd = Argument + ArgumentLen;
+        const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|');
+        assert(ScanFormat(Pipe + 1, ArgumentEnd, '|') == ArgumentEnd &&
+               "Found too many '|'s in a %diff modifier!");
         const char *FirstDollar = ScanFormat(Argument, Pipe, '$');
         const char *SecondDollar = ScanFormat(FirstDollar + 1, Pipe, '$');
         const char ArgStr1[] = { '%', static_cast<char>('0' + ArgNo) };