r314462 - [Sema] Correct nothrow inherited by noexcept

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 28 13:47:10 PDT 2017


Author: erichkeane
Date: Thu Sep 28 13:47:10 2017
New Revision: 314462

URL: http://llvm.org/viewvc/llvm-project?rev=314462&view=rev
Log:
[Sema] Correct nothrow inherited by noexcept

As reported in https://bugs.llvm.org/show_bug.cgi?id=33235,
a noexcept function was unable to inherit from a nothrow defaulted
constructor. Attribute "nothrow" is supposed to be semantically
identical to noexcept, and in fact, a number of other places in the
code treat them identically.

This patch simply checks the RecordDecl for the correct attribute in
the case where no other exception specifier was set.

Differential Revision: https://reviews.llvm.org/D38209

Added:
    cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp   (with props)
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=314462&r1=314461&r2=314462&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep 28 13:47:10 2017
@@ -167,6 +167,9 @@ Sema::ImplicitExceptionSpecification::Ca
   if (ComputedEST == EST_None)
     return;
 
+  if (EST == EST_None && Method->hasAttr<NoThrowAttr>())
+    EST = EST_BasicNoexcept;
+
   switch(EST) {
   // If this function can throw any exceptions, make a note of that.
   case EST_MSAny:

Added: cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp?rev=314462&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp (added)
+++ cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp Thu Sep 28 13:47:10 2017
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -fcxx-exceptions -fsyntax-only -Wexceptions -verify -std=c++14
+
+// expected-no-diagnostics
+struct Base {
+  __attribute__((nothrow)) Base() {}
+};
+
+struct Derived : Base {
+  Derived() noexcept = default;
+};
+
+struct Base2 {
+   Base2() noexcept {}
+};
+
+struct Derived2 : Base2 {
+  __attribute__((nothrow)) Derived2() = default;
+};
+
+struct Base3 {
+  __attribute__((nothrow)) Base3() {}
+};
+
+struct Derived3 : Base3 {
+  __attribute__((nothrow)) Derived3() = default;
+};

Propchange: cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/SemaCXX/nothrow-as-noexcept-ctor.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the cfe-commits mailing list