diff --git a/clang/docs/InternalsManual.html b/clang/docs/InternalsManual.html index 76b0c6764468..6a6736891687 100644 --- a/clang/docs/InternalsManual.html +++ b/clang/docs/InternalsManual.html @@ -361,7 +361,8 @@ Clang:

"diff" format Example:"no known conversion %diff{from | to | }1,2" Class:QualType -Description

This formatter takes two QualTypes and attempts to print a template difference between the two. If tree printing is off, the entire text inside the the braces is printed, with the formatted text replacing the pipes. If tree printing is on, the text is not printed and a type tree is printed after the diagnostic message.

+Description

This formatter takes two QualTypes and attempts to print a template difference between the two. If tree printing is off, the text inside the the braces before the pipe is printed, with the formatted text replacing the $. If tree printing is on, the text after the pipe is printed and a type tree is printed after the diagnostic message. +

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 6ba2353b341f..4ebceed5bf03 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1150,22 +1150,21 @@ def err_init_conversion_failed : Error< "%select{none|const|restrict|const and restrict|volatile|const and volatile|" "volatile and restrict|const, volatile, and restrict}6)}4">; -def err_lvalue_to_rvalue_ref : Error<"rvalue reference to type %0 cannot bind " - "to lvalue of type %1">; +def err_lvalue_to_rvalue_ref : Error<"rvalue reference %diff{to type $ cannot " + "bind to lvalue of type $|cannot bind to incompatible lvalue}0,1">; def err_lvalue_reference_bind_to_initlist : Error< "%select{non-const|volatile}0 lvalue reference to type %1 cannot bind to an " "initializer list temporary">; def err_lvalue_reference_bind_to_temporary : Error< - "%select{non-const|volatile}0 lvalue reference to type %1 cannot bind to a " - "temporary of type %2">; + "%select{non-const|volatile}0 lvalue reference %diff{to type $ cannot bind " + "to a temporary of type $|cannot bind to incompatible temporary}1,2">; def err_lvalue_reference_bind_to_unrelated : Error< - "%select{non-const|volatile}0 lvalue reference to type %1 cannot bind to a " - "value of unrelated type %2">; + "%select{non-const|volatile}0 lvalue reference %diff{to type $ cannot bind to a value of unrelated type $|cannot bind to a value of related type}1,2">; def err_reference_bind_drops_quals : Error< - "binding of reference to type %0 to a value of type %1 drops qualifiers">; + "binding of reference %diff{to type $ to a value of type $ drops " + "qualifiers|drops qualifiers}0,1">; def err_reference_bind_failed : Error< - "reference to type %0 could not bind to an %select{rvalue|lvalue}1 of type " - "%2">; + "reference %diff{to type $ could not bind to an %select{rvalue|lvalue}1 of type $|could not bing to %select{rvalue|lvalue}}0,2">; def err_reference_bind_init_list : Error< "reference to type %0 cannot bind to an initializer list">; def warn_temporary_array_to_pointer_decay : Warning< @@ -2169,7 +2168,7 @@ def note_ovl_candidate_bad_conv : Note<"candidate " "function (the implicit copy assignment operator)|" "function (the implicit move assignment operator)|" "constructor (inherited)}0%1" - " not viable: no known conversion %diff{from | to | }2,3for " + " not viable: no known conversion %diff{from $ to $ |}2,3for " "%select{%ordinal5 argument|object argument}4" "%select{|; dereference the argument with *|" "; take the address of the argument with &|" diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 6bf3102b1de0..d5ccd64f875b 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -823,6 +823,9 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd, TDT.ShowColors = getDiags()->ShowColors; intptr_t val = reinterpret_cast(&TDT); + const char *ArgumentEnd = Argument + ArgumentLen; + const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|'); + // Print the tree. if (getDiags()->PrintTemplateTree) { TDT.PrintFromType = true; @@ -834,18 +837,19 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd, FormattedArgs.size(), Tree, QualTypeVals); // If there is no tree information, fall back to regular printing. - if (!Tree.empty()) + if (!Tree.empty()) { + FormatDiagnostic(Pipe + 1, ArgumentEnd, OutStr); break; + } } // Non-tree printing, also the fall-back when tree printing fails. // The fall-back is triggered when the types compared are not templates. - const char *ArgumentEnd = Argument + ArgumentLen; - const char *FirstPipe = ScanFormat(Argument, ArgumentEnd, '|'); - const char *SecondPipe = ScanFormat(FirstPipe + 1, ArgumentEnd, '|'); + const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$'); + const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$'); // Append before text - FormatDiagnostic(Argument, FirstPipe, OutStr); + FormatDiagnostic(Argument, FirstDollar, OutStr); // Append first type TDT.PrintTree = false; @@ -856,7 +860,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd, FormattedArgs.data(), FormattedArgs.size(), OutStr, QualTypeVals); // Append middle text - FormatDiagnostic(FirstPipe + 1, SecondPipe, OutStr); + FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr); // Append second type TDT.PrintFromType = false; @@ -866,7 +870,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd, FormattedArgs.data(), FormattedArgs.size(), OutStr, QualTypeVals); // Append end text - FormatDiagnostic(SecondPipe + 1, ArgumentEnd, OutStr); + FormatDiagnostic(SecondDollar + 1, Pipe, OutStr); break; } diff --git a/clang/test/Misc/diag-template-diffing-color.cpp b/clang/test/Misc/diag-template-diffing-color.cpp index 502f6843af73..b944ef2bb0c7 100644 --- a/clang/test/Misc/diag-template-diffing-color.cpp +++ b/clang/test/Misc/diag-template-diffing-color.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -fcolor-diagnostics %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -fcolor-diagnostics -fdiagnostics-show-template-tree %s 2>&1 | FileCheck %s -check-prefix=TREE // XFAIL: mingw32,win32 template struct foo {}; void func(foo); @@ -6,3 +7,13 @@ int main() { func(foo()); } // CHECK: {{.*}}candidate function not viable: no known conversion from 'foo<{{.}}[0;1;36mdouble{{.}}[0m>' to 'foo<{{.}}[0;1;36mint{{.}}[0m>' for 1st argument{{.}}[0m +// TREE: candidate function not viable: no known conversion for 1st argument +// TREE: foo< +// TREE: [{{.}}[0;1;36mdouble{{.}}[0m != {{.}}[0;1;36mint{{.}}[0m]>{{.}}[0m + +foo A; +foo &B = A; +// CHECK: {{.*}}non-const lvalue reference to type 'foo<{{.}}[0;1;36mdouble{{.}}[0m{{.}}[1m>' cannot bind to a value of unrelated type 'foo<{{.}}[0;1;36mint{{.}}[0m{{.}}[1m>'{{.}}[0m +// TREE: non-const lvalue reference cannot bind to a value of related type +// TREE: foo< +// TREE: [{{.}}[0;1;36mdouble{{.}}[0m{{.}}[1m != {{.}}[0;1;36mint{{.}}[0m{{.}}[1m]>{{.}}[0m