]> granicus.if.org Git - clang/commitdiff
Preserve the "last diagnostic was suppressed" flag across SFINAE checks.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 30 Nov 2017 08:18:21 +0000 (08:18 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 30 Nov 2017 08:18:21 +0000 (08:18 +0000)
Sometimes we check the validity of some construct between producing a
diagnostic and producing its notes. Ideally, we wouldn't do that, but in
practice running code that "cannot possibly produce a diagnostic" in such a
situation should be safe, and reasonable factoring of some code requires it
with our current diagnostics infrastruture. If this does happen, a diagnostic
that's suppressed due to SFINAE should not cause notes connected to the prior
diagnostic to be suppressed.

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

include/clang/Basic/Diagnostic.h
include/clang/Sema/Sema.h
test/CXX/drs/dr4xx.cpp
test/SemaCXX/overload-call.cpp

index 22cded21c12df620abc619cd1e006cf1f24462db..a7458d45618ee8482457550ba8dab80070fab272 100644 (file)
@@ -575,13 +575,15 @@ public:
   OverloadsShown getShowOverloads() const { return ShowOverloads; }
   
   /// \brief Pretend that the last diagnostic issued was ignored, so any
-  /// subsequent notes will be suppressed.
+  /// subsequent notes will be suppressed, or restore a prior ignoring
+  /// state after ignoring some diagnostics and their notes, possibly in
+  /// the middle of another diagnostic.
   ///
   /// This can be used by clients who suppress diagnostics themselves.
-  void setLastDiagnosticIgnored() {
+  void setLastDiagnosticIgnored(bool Ignored = true) {
     if (LastDiagLevel == DiagnosticIDs::Fatal)
       FatalErrorOccurred = true;
-    LastDiagLevel = DiagnosticIDs::Ignored;
+    LastDiagLevel = Ignored ? DiagnosticIDs::Ignored : DiagnosticIDs::Warning;
   }
 
   /// \brief Determine whether the previous diagnostic was ignored. This can
index 376df4ad66a2f86d89eec85252dcd2ad9e434630..4ca56ab1012c3f817686664ce70ee202ead6549a 100644 (file)
@@ -7428,13 +7428,16 @@ public:
     unsigned PrevSFINAEErrors;
     bool PrevInNonInstantiationSFINAEContext;
     bool PrevAccessCheckingSFINAE;
+    bool PrevLastDiagnosticIgnored;
 
   public:
     explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
       : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
         PrevInNonInstantiationSFINAEContext(
                                       SemaRef.InNonInstantiationSFINAEContext),
-        PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
+        PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE),
+        PrevLastDiagnosticIgnored(
+            SemaRef.getDiagnostics().isLastDiagnosticIgnored())
     {
       if (!SemaRef.isSFINAEContext())
         SemaRef.InNonInstantiationSFINAEContext = true;
@@ -7446,6 +7449,8 @@ public:
       SemaRef.InNonInstantiationSFINAEContext
         = PrevInNonInstantiationSFINAEContext;
       SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
+      SemaRef.getDiagnostics().setLastDiagnosticIgnored(
+          PrevLastDiagnosticIgnored);
     }
 
     /// \brief Determine whether any SFINAE errors have been trapped.
index 2e6a261ad0cc410e712efbae3c614451d3a924ef..d27adc428d5121633ee27a684118c340ca71928b 100644 (file)
@@ -22,6 +22,9 @@ namespace dr401 { // dr401: yes
   class B {
   protected:
     typedef int type; // expected-note {{protected}}
+#if __cplusplus == 199711L
+    // expected-note@-2 {{protected}}
+#endif
   };
 
   class C {
index 0e3a9ee50bb241a0daac3f0231bf00ee303e3e13..0c4bba5027f7ee23fa20a0980dccc8bbfc3d0cd8 100644 (file)
@@ -658,3 +658,11 @@ namespace StringLiteralToCharAmbiguity {
   // expected-note@-5 {{candidate function}}
 #endif
 }
+
+namespace ProduceNotesAfterSFINAEFailure {
+  struct A {
+    template<typename T, typename U = typename T::x> A(T); // expected-warning 0-1{{extension}}
+  };
+  void f(void*, A); // expected-note {{candidate function not viable}}
+  void g() { f(1, 2); } // expected-error {{no matching function}}
+}