From: Chandler Carruth Date: Fri, 23 Dec 2016 05:19:47 +0000 (+0000) Subject: Add an assert to catch improperly constructed %diff sequences in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49f60224fccab81034b429773e04f25031ffedcf;p=clang Add an assert to catch improperly constructed %diff sequences in 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 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a957924587..3b43a6474f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 1f4316af3f..7529c475d6 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -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('0' + ArgNo) };