aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2012-02-29 12:47:43 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2012-02-29 12:47:43 +0000
commit51ad9cd0644c9acf442f049aed98b66f7b1041a2 (patch)
tree6563eb1f5b0c564aa5af61048ad85257f47d394a
parent16f1f717af196b1448258857b2e6dcfe144b39d0 (diff)
Tentatively fix PR12117. The test case from the bug now passes, and all existing tests still pass, but there may still be corner cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151716 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaInit.cpp19
-rw-r--r--test/SemaCXX/cxx0x-initializer-constructor.cpp6
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index a9adcbf8bc..ba4453c08c 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -2795,7 +2795,7 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
DeclContext::lookup_iterator ConEnd,
OverloadCandidateSet::iterator &Best,
bool CopyInitializing, bool AllowExplicit,
- bool OnlyListConstructors) {
+ bool OnlyListConstructors, bool InitListSyntax) {
CandidateSet.clear();
for (; Con != ConEnd; ++Con) {
@@ -2813,9 +2813,10 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
Constructor = cast<CXXConstructorDecl>(D);
// If we're performing copy initialization using a copy constructor, we
- // suppress user-defined conversions on the arguments.
- // FIXME: Move constructors?
- if (CopyInitializing && Constructor->isCopyConstructor())
+ // suppress user-defined conversions on the arguments. We do the same for
+ // move constructors.
+ if ((CopyInitializing || (InitListSyntax && NumArgs == 1)) &&
+ Constructor->isCopyOrMoveConstructor())
SuppressUserConversions = true;
}
@@ -2825,8 +2826,8 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
if (ConstructorTmpl)
S.AddTemplateOverloadCandidate(ConstructorTmpl, FoundDecl,
/*ExplicitArgs*/ 0,
- llvm::makeArrayRef(Args, NumArgs), CandidateSet,
- SuppressUserConversions);
+ llvm::makeArrayRef(Args, NumArgs),
+ CandidateSet, SuppressUserConversions);
else {
// C++ [over.match.copy]p1:
// - When initializing a temporary to be bound to the first parameter
@@ -2919,7 +2920,8 @@ static void TryConstructorInitialization(Sema &S,
Result = ResolveConstructorOverload(S, Kind.getLocation(), Args, NumArgs,
CandidateSet, ConStart, ConEnd, Best,
CopyInitialization, AllowExplicit,
- /*OnlyListConstructor=*/true);
+ /*OnlyListConstructor=*/true,
+ InitListSyntax);
// Time to unwrap the init list.
InitListExpr *ILE = cast<InitListExpr>(Args[0]);
@@ -2937,7 +2939,8 @@ static void TryConstructorInitialization(Sema &S,
Result = ResolveConstructorOverload(S, Kind.getLocation(), Args, NumArgs,
CandidateSet, ConStart, ConEnd, Best,
CopyInitialization, AllowExplicit,
- /*OnlyListConstructors=*/false);
+ /*OnlyListConstructors=*/false,
+ InitListSyntax);
}
if (Result) {
Sequence.SetOverloadFailure(InitListSyntax ?
diff --git a/test/SemaCXX/cxx0x-initializer-constructor.cpp b/test/SemaCXX/cxx0x-initializer-constructor.cpp
index 5e686d7152..14420d94dd 100644
--- a/test/SemaCXX/cxx0x-initializer-constructor.cpp
+++ b/test/SemaCXX/cxx0x-initializer-constructor.cpp
@@ -212,3 +212,9 @@ namespace PR12092 {
}
}
+
+namespace PR12117 {
+ struct A { A(int); };
+ struct B { B(A); } b{{0}};
+ struct C { C(int); } c{0};
+}