r362236 - Suppress nothrow/exception spec conflict warning when ES is parsed.

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri May 31 08:56:27 PDT 2019


Author: erichkeane
Date: Fri May 31 08:56:27 2019
New Revision: 362236

URL: http://llvm.org/viewvc/llvm-project?rev=362236&view=rev
Log:
Suppress nothrow/exception spec conflict warning when ES is parsed.

The previously added warning ended up causing false positives when
nothrow was used on member functions, where the exception specification
wasn't yet parsed.  So, throw() and noexcept(true) both were incorrectly
warning.  There doesn't seem to be a good way to force these to be parsed
to identify which they are (and likely should not be), so suppress the warning.

For now, unevaluated/uninstantiated are left as warnings as I am not
creative enough to find a reproducer that causes a false positive for
either.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=362236&r1=362235&r2=362236&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri May 31 08:56:27 2019
@@ -6976,7 +6976,10 @@ static bool handleFunctionTypeAttr(TypeP
       case EST_BasicNoexcept:
       case EST_NoexceptTrue:
       case EST_NoThrow:
+      case EST_Unparsed:
         // Exception spec doesn't conflict with nothrow, so don't warn.
+        // Unparsed is included in this, since method signatures aren't parsed
+        // until after the fact.
         break;
 
       case EST_Dynamic:
@@ -6985,7 +6988,6 @@ static bool handleFunctionTypeAttr(TypeP
       case EST_DependentNoexcept:
       case EST_Unevaluated:
       case EST_Uninstantiated:
-      case EST_Unparsed:
         S.Diag(attr.getLoc(), diag::warn_nothrow_attribute_ignored);
         break;
       }

Modified: cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp?rev=362236&r1=362235&r2=362236&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp (original)
+++ cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp Fri May 31 08:56:27 2019
@@ -53,3 +53,16 @@ __declspec(nothrow) void foo4() noexcept
 __declspec(nothrow) void foo5() noexcept(noexcept(foo2()));
 // expected-warning at +1{{'nothrow' attribute conflicts with exception specification; attribute ignored}}
 __declspec(nothrow) void foo6() noexcept(noexcept(foo3()));
+
+// FIXME: It would be nice to be able to warn on these, however at the time we
+// evaluate the nothrow, these have yet to be parsed, so the data is not yet
+// there.
+struct S {
+  __declspec(nothrow) void f1();
+#ifndef CPP17
+  __declspec(nothrow) void f2() throw();
+  __declspec(nothrow) void f3() throw(int);
+#endif
+  __declspec(nothrow) void f4() noexcept(true);
+  __declspec(nothrow) void f5() noexcept(false);
+};




More information about the cfe-commits mailing list