[cfe-commits] r116411 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Sema/Sema.cpp test/SemaTemplate/temp_arg_nontype.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 13 10:22:14 PDT 2010


Author: dgregor
Date: Wed Oct 13 12:22:14 2010
New Revision: 116411

URL: http://llvm.org/viewvc/llvm-project?rev=116411&view=rev
Log:
Fix a silly bug in the suppression of non-error diagnostics in a
SFINAE context, where we weren't getting the right diagnostic argument
count. I blame DiagnosticBuilder's weirdness. Fixes PR8372.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=116411&r1=116410&r2=116411&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Oct 13 12:22:14 2010
@@ -669,6 +669,9 @@
     : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixItHints(0) {}
 
   friend class PartialDiagnostic;
+
+protected:
+  void FlushCounts();
   
 public:
   /// Copy constructor.  When copied, this "takes" the diagnostic info from the

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=116411&r1=116410&r2=116411&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Oct 13 12:22:14 2010
@@ -625,6 +625,12 @@
   return true;
 }
 
+void DiagnosticBuilder::FlushCounts() {
+  DiagObj->NumDiagArgs = NumArgs;
+  DiagObj->NumDiagRanges = NumRanges;
+  DiagObj->NumFixItHints = NumFixItHints;
+}
+
 bool DiagnosticBuilder::Emit() {
   // If DiagObj is null, then its soul was stolen by the copy ctor
   // or the user called Emit().
@@ -632,9 +638,7 @@
 
   // When emitting diagnostics, we set the final argument count into
   // the Diagnostic object.
-  DiagObj->NumDiagArgs = NumArgs;
-  DiagObj->NumDiagRanges = NumRanges;
-  DiagObj->NumFixItHints = NumFixItHints;
+  FlushCounts();
 
   // Process the diagnostic, sending the accumulated information to the
   // DiagnosticClient.

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=116411&r1=116410&r2=116411&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Oct 13 12:22:14 2010
@@ -455,7 +455,9 @@
     case Diagnostic::SFINAE_Suppress:
       // Make a copy of this suppressed diagnostic and store it with the
       // template-deduction information;
+      FlushCounts();
       DiagnosticInfo DiagInfo(&SemaRef.Diags);
+        
       Info->addSuppressedDiagnostic(DiagInfo.getLocation(),
                         PartialDiagnostic(DiagInfo,
                                           SemaRef.Context.getDiagAllocator()));

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=116411&r1=116410&r2=116411&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp Wed Oct 13 12:22:14 2010
@@ -243,3 +243,8 @@
     B<&c03> b03;
   }
 }
+
+namespace PR8372 {
+  template <int I> void foo() { } // expected-note{{template parameter is declared here}}
+  void bar() { foo <0x80000000> (); } // expected-warning{{non-type template argument value '2147483648' truncated to '-2147483648' for template parameter of type 'int'}}
+}





More information about the cfe-commits mailing list