[PATCH] D25719: [Sema] Fix PR30664
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 03:23:53 PDT 2016
arphaman created this revision.
arphaman added a reviewer: rsmith.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.
This patch fixes an assertion failure crash that happens when a constant record reference member is initialized using an empty initializer list.
Repository:
rL LLVM
https://reviews.llvm.org/D25719
Files:
lib/Sema/SemaExprCXX.cpp
test/SemaCXX/cxx11-crashes.cpp
Index: test/SemaCXX/cxx11-crashes.cpp
===================================================================
--- test/SemaCXX/cxx11-crashes.cpp
+++ test/SemaCXX/cxx11-crashes.cpp
@@ -91,3 +91,33 @@
Foo(lambda);
}
}
+
+namespace pr30664 {
+struct foo {
+ int x;
+ foo() : x(42) { }
+};
+
+struct bar {
+ const foo &o; // expected-note {{reference member declared here}}
+ bar() : o{} {} // expected-warning {{binding reference member 'o' to a temporary value}}
+};
+
+struct outer {
+ struct inner {
+ const outer &o; // expected-note {{reference member declared here}}
+ inner() : o({}) {} // expected-warning {{binding reference member 'o' to a temporary value}}
+ };
+};
+
+outer::inner i;
+
+struct foobar {
+ foobar(void) { }
+ struct inner {
+ int y;
+ const foobar &o; // expected-note {{reference member declared here}}
+ inner() : y(21), o({}) {} // expected-warning {{binding reference member 'o' to a temporary value}}
+ };
+};
+}
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -3426,8 +3426,12 @@
if (!ICS.UserDefined.EllipsisConversion) {
// If the user-defined conversion is specified by a constructor, the
// initial standard conversion sequence converts the source type to
- // the type required by the argument of the constructor
- BeforeToType = Ctor->getParamDecl(0)->getType().getNonReferenceType();
+ // the type required by the argument of the constructor or the 'void'
+ // type if the argument has no constructors.
+ BeforeToType =
+ Ctor->param_empty()
+ ? Context.VoidTy
+ : Ctor->getParamDecl(0)->getType().getNonReferenceType();
}
}
// Watch out for ellipsis conversion.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25719.74963.patch
Type: text/x-patch
Size: 1888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161018/dbb42817/attachment.bin>
More information about the cfe-commits
mailing list