From 8621d01b253e3f36976d75dd999bdc0f21d9e5d9 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 19 Oct 2009 21:30:45 +0000 Subject: [PATCH] Add the built-in candidate set reduction hueristic to '+=', '-=', '*=' and '/=' builtin operators and fixes a logic bug exposed by doing this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84538 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOverload.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 436b3d1e27..44c3e2dd3f 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3201,6 +3201,9 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, // that make use of these types. Qualifiers VisibleTypeConversionsQuals; VisibleTypeConversionsQuals.addConst(); + for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx) + VisibleTypeConversionsQuals += CollectVRQualifiers(Context, Args[ArgIdx]); + BuiltinCandidateTypeSet CandidateTypes(*this); if (Op == OO_Less || Op == OO_Greater || Op == OO_LessEqual || Op == OO_GreaterEqual || Op == OO_EqualEqual || Op == OO_ExclaimEqual || @@ -3208,9 +3211,6 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, Op == OO_PlusEqual || Op == OO_MinusEqual || Op == OO_Subscript || Op == OO_ArrowStar || Op == OO_PlusPlus || Op == OO_MinusMinus || (Op == OO_Star && NumArgs == 1) || Op == OO_Conditional) { - for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx) - VisibleTypeConversionsQuals += CollectVRQualifiers(Context, Args[ArgIdx]); - for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx) CandidateTypes.AddTypesConvertedFrom(Args[ArgIdx]->getType(), true, @@ -3636,7 +3636,8 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet, /*IsAssigmentOperator=*/Op == OO_Equal); - if (!Context.getCanonicalType(*Ptr).isVolatileQualified()) { + if (!Context.getCanonicalType(*Ptr).isVolatileQualified() && + VisibleTypeConversionsQuals.hasVolatile()) { // volatile version ParamTypes[0] = Context.getLValueReferenceType(Context.getVolatileType(*Ptr)); @@ -3672,10 +3673,12 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, /*IsAssigmentOperator=*/Op == OO_Equal); // Add this built-in operator as a candidate (VQ is 'volatile'). - ParamTypes[0] = Context.getVolatileType(ArithmeticTypes[Left]); - ParamTypes[0] = Context.getLValueReferenceType(ParamTypes[0]); - AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet, - /*IsAssigmentOperator=*/Op == OO_Equal); + if (VisibleTypeConversionsQuals.hasVolatile()) { + ParamTypes[0] = Context.getVolatileType(ArithmeticTypes[Left]); + ParamTypes[0] = Context.getLValueReferenceType(ParamTypes[0]); + AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet, + /*IsAssigmentOperator=*/Op == OO_Equal); + } } } break; -- 2.40.0