[cfe-commits] r159463 - in /cfe/trunk: docs/InternalsManual.html include/clang/Basic/DiagnosticSemaKinds.td lib/Basic/Diagnostic.cpp test/Misc/diag-template-diffing-color.cpp

Richard Trieu rtrieu at google.com
Fri Jun 29 14:12:17 PDT 2012


Author: rtrieu
Date: Fri Jun 29 16:12:16 2012
New Revision: 159463

URL: http://llvm.org/viewvc/llvm-project?rev=159463&view=rev
Log:
Update the %diff modifer to have an alternate string print when a template tree
is selected.  This will allow more flexibility when converting diagnostics to
use template type diffing.

Also updated the internal manual and test cases for correctly keeping the bold
attribute and for tree printing.

Modified:
    cfe/trunk/docs/InternalsManual.html
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/test/Misc/diag-template-diffing-color.cpp

Modified: cfe/trunk/docs/InternalsManual.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/InternalsManual.html?rev=159463&r1=159462&r2=159463&view=diff
==============================================================================
--- cfe/trunk/docs/InternalsManual.html (original)
+++ cfe/trunk/docs/InternalsManual.html Fri Jun 29 16:12:16 2012
@@ -361,7 +361,8 @@
 <tr><td colspan="2"><b>"diff" format</b></td></tr>
 <tr><td>Example:</td><td><tt>"no known conversion %diff{from | to | }1,2"</tt></td></tr>
 <tr><td>Class:</td><td>QualType</td></tr>
-<tr><td>Description</td><td><p>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.</p></td></tr>
+<tr><td>Description</td><td><p>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.
+</p></td></tr>
     
 </table>
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=159463&r1=159462&r2=159463&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 29 16:12:16 2012
@@ -1150,22 +1150,21 @@
   "%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 @@
     "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 &|"

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=159463&r1=159462&r2=159463&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Fri Jun 29 16:12:16 2012
@@ -823,6 +823,9 @@
       TDT.ShowColors = getDiags()->ShowColors;
       intptr_t val = reinterpret_cast<intptr_t>(&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 @@
                                        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 @@
                                      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 @@
                                      FormattedArgs.data(), FormattedArgs.size(),
                                      OutStr, QualTypeVals);
       // Append end text
-      FormatDiagnostic(SecondPipe + 1, ArgumentEnd, OutStr);
+      FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
       break;
     }
     

Modified: cfe/trunk/test/Misc/diag-template-diffing-color.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-template-diffing-color.cpp?rev=159463&r1=159462&r2=159463&view=diff
==============================================================================
--- cfe/trunk/test/Misc/diag-template-diffing-color.cpp (original)
+++ cfe/trunk/test/Misc/diag-template-diffing-color.cpp Fri Jun 29 16:12:16 2012
@@ -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<typename> struct foo {};
 void func(foo<int>);
@@ -6,3 +7,13 @@
   func(foo<double>());
 }
 // 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<int> A;
+foo<double> &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





More information about the cfe-commits mailing list