[PATCH] D27116: Fix crash when using __has_nothrow_copy with inherited constructors

Philippe Daouadi via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 24 14:59:00 PST 2016


blastrock created this revision.
blastrock added reviewers: CornedBee, aaron.ballman.
blastrock added a subscriber: llvm-commits.

Fixes PR30491


https://reviews.llvm.org/D27116

Files:
  lib/Sema/SemaExprCXX.cpp
  test/CXX/special/class.copy/p34-cxx11.cpp


Index: test/CXX/special/class.copy/p34-cxx11.cpp
===================================================================
--- /dev/null
+++ test/CXX/special/class.copy/p34-cxx11.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// expected-no-diagnostics
+
+struct A {
+  A(A const &) noexcept(false) {}
+};
+
+struct B : public A {
+  using A::A;
+};
+
+static_assert(!__has_nothrow_copy(B), "has_nothrow_copy fails");
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4418,7 +4418,17 @@
         // resolution point.
         if (isa<FunctionTemplateDecl>(ND))
           continue;
-        const CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(ND);
+        const CXXConstructorDecl *Constructor;
+        // handle inherited constructors
+        if (isa<UsingDecl>(ND))
+        {
+          const auto *UD = cast<UsingDecl>(ND);
+          assert(UD->shadow_size() == 1);
+          Constructor =
+              cast<CXXConstructorDecl>(UD->shadow_begin()->getTargetDecl());
+        }
+        else
+          Constructor = cast<CXXConstructorDecl>(ND);
         if (Constructor->isCopyConstructor(FoundTQs)) {
           FoundConstructor = true;
           const FunctionProtoType *CPT


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27116.79262.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161124/bff7049e/attachment.bin>


More information about the llvm-commits mailing list