Skip to content

Commit 6098fd1

Browse files
committedSep 3, 2016
[Sema] Fix how we set implicit conversion kinds.
We have invariants we like to guarantee for the `ImplicitConversionKind`s in a `StandardConversionSequence`. These weren't being upheld in code that r280553 touched, so Richard suggested that we should fix that. See D24113. I'm not entirely sure how to go about testing this, so no test case is included. Suggestions welcome. llvm-svn: 280562
1 parent 4efaa30 commit 6098fd1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
 

‎clang/lib/Sema/SemaOverload.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -1790,29 +1790,35 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
17901790
/*Diagnose=*/false,
17911791
/*DiagnoseCFAudited=*/false,
17921792
/*ConvertRHS=*/false);
1793-
ImplicitConversionKind ImplicitConv;
1793+
ImplicitConversionKind SecondConv;
17941794
switch (Conv) {
17951795
case Sema::Compatible:
1796-
ImplicitConv = ICK_C_Only_Conversion;
1796+
SecondConv = ICK_C_Only_Conversion;
17971797
break;
17981798
// For our purposes, discarding qualifiers is just as bad as using an
17991799
// incompatible pointer. Note that an IncompatiblePointer conversion can drop
18001800
// qualifiers, as well.
18011801
case Sema::CompatiblePointerDiscardsQualifiers:
18021802
case Sema::IncompatiblePointer:
18031803
case Sema::IncompatiblePointerSign:
1804-
ImplicitConv = ICK_Incompatible_Pointer_Conversion;
1804+
SecondConv = ICK_Incompatible_Pointer_Conversion;
18051805
break;
18061806
default:
18071807
return false;
18081808
}
18091809

1810-
SCS.setAllToTypes(ToType);
1811-
// We need to set all three because we want this conversion to rank terribly,
1812-
// and we don't know what conversions it may overlap with.
1813-
SCS.First = ImplicitConv;
1814-
SCS.Second = ImplicitConv;
1815-
SCS.Third = ImplicitConv;
1810+
// First can only be an lvalue conversion, so we pretend that this was the
1811+
// second conversion. First should already be valid from earlier in the
1812+
// function.
1813+
SCS.Second = SecondConv;
1814+
SCS.setToType(1, ToType);
1815+
1816+
// Third is Identity, because Second should rank us worse than any other
1817+
// conversion. This could also be ICK_Qualification, but it's simpler to just
1818+
// lump everything in with the second conversion, and we don't gain anything
1819+
// from making this ICK_Qualification.
1820+
SCS.Third = ICK_Identity;
1821+
SCS.setToType(2, ToType);
18161822
return true;
18171823
}
18181824

0 commit comments

Comments
 (0)