r290227 - [c++1z] When initializing a const-qualified class type, don't forget to add on
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 20 17:31:57 PST 2016
Author: rsmith
Date: Tue Dec 20 19:31:56 2016
New Revision: 290227
URL: http://llvm.org/viewvc/llvm-project?rev=290227&view=rev
Log:
[c++1z] When initializing a const-qualified class type, don't forget to add on
the requested cv-qualifiers after construction. This usually doesn't matter,
but it does matter within a ?: operator.
Added:
cfe/trunk/test/CXX/expr/expr.cond/p4.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=290227&r1=290226&r2=290227&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Dec 20 19:31:56 2016
@@ -5199,8 +5199,7 @@ static bool TryClassUnification(Sema &Se
//
// This actually refers very narrowly to the lvalue-to-rvalue conversion, not
// to the array-to-pointer or function-to-pointer conversions.
- if (!TTy->getAs<TagType>())
- TTy = TTy.getUnqualifiedType();
+ TTy = TTy.getNonLValueExprType(Self.Context);
InitializedEntity Entity = InitializedEntity::InitializeTemporary(TTy);
InitializationSequence InitSeq(Self, Entity, Kind, From);
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=290227&r1=290226&r2=290227&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Dec 20 19:31:56 2016
@@ -3609,17 +3609,7 @@ static void TryConstructorInitialization
UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isRValue() &&
S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) {
// Convert qualifications if necessary.
- QualType InitType = UnwrappedArgs[0]->getType();
- ImplicitConversionSequence ICS;
- ICS.setStandard();
- ICS.Standard.setAsIdentityConversion();
- ICS.Standard.setFromType(InitType);
- ICS.Standard.setAllToTypes(InitType);
- if (!S.Context.hasSameType(InitType, DestType)) {
- ICS.Standard.Third = ICK_Qualification;
- ICS.Standard.setToType(2, DestType);
- }
- Sequence.AddConversionSequenceStep(ICS, DestType);
+ Sequence.AddQualificationConversionStep(DestType, VK_RValue);
if (ILE)
Sequence.RewrapReferenceInitList(DestType, ILE);
return;
@@ -4790,6 +4780,8 @@ static void TryUserDefinedConversion(Sem
// FIXME: Mark this copy as extraneous.
if (!S.getLangOpts().CPlusPlus1z)
Sequence.AddFinalCopy(DestType);
+ else if (DestType.hasQualifiers())
+ Sequence.AddQualificationConversionStep(DestType, VK_RValue);
return;
}
@@ -4812,6 +4804,8 @@ static void TryUserDefinedConversion(Sem
Function->getReturnType()->isReferenceType() ||
!S.Context.hasSameUnqualifiedType(ConvType, DestType))
Sequence.AddFinalCopy(DestType);
+ else if (!S.Context.hasSameType(ConvType, DestType))
+ Sequence.AddQualificationConversionStep(DestType, VK_RValue);
return;
}
Added: cfe/trunk/test/CXX/expr/expr.cond/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.cond/p4.cpp?rev=290227&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.cond/p4.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.cond/p4.cpp Tue Dec 20 19:31:56 2016
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++98 -verify %s
+// RUN: %clang_cc1 -std=c++1z -verify %s
+
+// expected-no-diagnostics
+
+struct A { A(); A(int); };
+void f() {
+ const A a;
+ true ? a : 0;
+}
More information about the cfe-commits
mailing list