PR7245: Make binding a reference to a temporary without a usable copy
constructor into an extension warning into the error that C++98 requires.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105529 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 10ff5ad..fed5e78 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2767,7 +2767,8 @@
AccessResult CheckConstructorAccess(SourceLocation Loc,
CXXConstructorDecl *D,
const InitializedEntity &Entity,
- AccessSpecifier Access);
+ AccessSpecifier Access,
+ bool IsCopyBindingRefToTemp = false);
AccessResult CheckDestructorAccess(SourceLocation Loc,
CXXDestructorDecl *Dtor,
const PartialDiagnostic &PDiag);
diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp
index 54d06f5..7845f6d 100644
--- a/lib/Sema/SemaAccess.cpp
+++ b/lib/Sema/SemaAccess.cpp
@@ -1157,9 +1157,10 @@
/// Checks access to a constructor.
Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
- CXXConstructorDecl *Constructor,
- const InitializedEntity &Entity,
- AccessSpecifier Access) {
+ CXXConstructorDecl *Constructor,
+ const InitializedEntity &Entity,
+ AccessSpecifier Access,
+ bool IsCopyBindingRefToTemp) {
if (!getLangOptions().AccessControl ||
Access == AS_public)
return AR_accessible;
@@ -1170,7 +1171,9 @@
QualType());
switch (Entity.getKind()) {
default:
- AccessEntity.setDiag(diag::err_access_ctor);
+ AccessEntity.setDiag(IsCopyBindingRefToTemp
+ ? diag::ext_rvalue_to_reference_access_ctor
+ : diag::err_access_ctor);
break;
case InitializedEntity::EK_Base:
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index ef99d1b..e34e168 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -3326,12 +3326,16 @@
break;
case OR_No_Viable_Function:
- S.Diag(Loc, diag::err_temp_copy_no_viable)
+ S.Diag(Loc, IsExtraneousCopy && !S.isSFINAEContext()
+ ? diag::ext_rvalue_to_reference_temp_copy_no_viable
+ : diag::err_temp_copy_no_viable)
<< (int)Entity.getKind() << CurInitExpr->getType()
<< CurInitExpr->getSourceRange();
S.PrintOverloadCandidates(CandidateSet, Sema::OCD_AllCandidates,
&CurInitExpr, 1);
- return S.ExprError();
+ if (!IsExtraneousCopy || S.isSFINAEContext())
+ return S.ExprError();
+ return move(CurInit);
case OR_Ambiguous:
S.Diag(Loc, diag::err_temp_copy_ambiguous)
@@ -3355,7 +3359,7 @@
CurInit.release(); // Ownership transferred into MultiExprArg, below.
S.CheckConstructorAccess(Loc, Constructor, Entity,
- Best->FoundDecl.getAccess());
+ Best->FoundDecl.getAccess(), IsExtraneousCopy);
if (IsExtraneousCopy) {
// If this is a totally extraneous copy for C++03 reference