]> granicus.if.org Git - clang/commitdiff
Fix stack overflow when trying to create an implicit moving
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Oct 2012 16:14:06 +0000 (16:14 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Oct 2012 16:14:06 +0000 (16:14 +0000)
constructor with invalid code.

rdar://12240916

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

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/cxx11-crashes.cpp [new file with mode: 0644]

index c898d81a61d80f35e3e263bb2749c91d4a7babfc..12452b2429b051fe7b52d78c7f5db9e54b50621a 100644 (file)
@@ -8154,7 +8154,7 @@ hasMoveOrIsTriviallyCopyable(Sema &S, QualType Type, bool IsConstructor) {
   // reference types, are supposed to return false here, but that appears
   // to be a standard defect.
   CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl();
-  if (!ClassDecl || !ClassDecl->getDefinition())
+  if (!ClassDecl || !ClassDecl->getDefinition() || ClassDecl->isInvalidDecl())
     return true;
 
   if (Type.isTriviallyCopyableType(S.Context))
diff --git a/test/SemaCXX/cxx11-crashes.cpp b/test/SemaCXX/cxx11-crashes.cpp
new file mode 100644 (file)
index 0000000..d5db109
--- /dev/null
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// rdar://12240916 stack overflow.
+namespace rdar12240916 {
+
+struct S2 {
+  S2(const S2&);
+  S2();
+};
+
+struct S { // expected-note {{not complete}}
+  S x; // expected-error {{incomplete type}}
+  S2 y;
+};
+
+S foo() {
+  S s;
+  return s;
+}
+
+struct S3; // expected-note {{forward declaration}}
+
+struct S4 {
+  S3 x; // expected-error {{incomplete type}}
+  S2 y;
+};
+
+struct S3 {
+  S4 x;
+  S2 y;
+};
+
+S4 foo2() {
+  S4 s;
+  return s;
+}
+
+}