summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-11-01 01:37:11 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-11-01 01:37:11 +0000
commit5173136a968547330ab5a25c467b9b968be9ab43 (patch)
treed795d97a8daf7ff69861f0d557f5296ff2cb5bf9 /clang/lib
parented017b634cc2fb6761dc292cb05f01cd12b0164f (diff)
downloadbcm5719-llvm-5173136a968547330ab5a25c467b9b968be9ab43.tar.gz
bcm5719-llvm-5173136a968547330ab5a25c467b9b968be9ab43.zip
[c++17] Refine resolution of constructor / conversion function disambiguation.
Given a choice between a constructor call and a conversion function in C++17, we prefer the constructor for direct-initialization and the conversion function for copy-initialization, matching the behavior in C++14 and before. The guaranteed copy elision rules were not intended to change the meaning of such code (other than by removing unnecessary copy constructor calls). This tweak will be raised with CWG. llvm-svn: 317066
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaOverload.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 8efb7c69d30..56135288db9 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -8977,6 +8977,18 @@ bool clang::isBetterOverloadCandidate(
// C++14 [over.match.best]p1 section 2 bullet 3.
}
+ // FIXME: Work around a defect in the C++17 guaranteed copy elision wording,
+ // as combined with the resolution to CWG issue 243.
+ //
+ // When the context is initialization by constructor ([over.match.ctor] or
+ // either phase of [over.match.list]), a constructor is preferred over
+ // a conversion function.
+ if (Kind == OverloadCandidateSet::CSK_InitByConstructor && NumArgs == 1 &&
+ Cand1.Function && Cand2.Function &&
+ isa<CXXConstructorDecl>(Cand1.Function) !=
+ isa<CXXConstructorDecl>(Cand2.Function))
+ return isa<CXXConstructorDecl>(Cand1.Function);
+
// -- F1 is a non-template function and F2 is a function template
// specialization, or, if not that,
bool Cand1IsSpecialization = Cand1.Function &&
@@ -9035,20 +9047,6 @@ bool clang::isBetterOverloadCandidate(
return true;
}
}
-
-
-
- // FIXME: Work around a defect in the C++17 guaranteed copy elision wording,
- // as combined with the resolution to CWG issue 243.
- //
- // When the context is initialization by constructor ([over.match.ctor] or
- // either phase of [over.match.list]), a constructor is preferred over
- // a conversion function.
- if (Kind == OverloadCandidateSet::CSK_InitByConstructor && NumArgs == 1 &&
- Cand1.Function && Cand2.Function &&
- isa<CXXConstructorDecl>(Cand1.Function) !=
- isa<CXXConstructorDecl>(Cand2.Function))
- return isa<CXXConstructorDecl>(Cand1.Function);
// Check for enable_if value-based overload resolution.
if (Cand1.Function && Cand2.Function) {
OpenPOWER on IntegriCloud