r280562 - [Sema] Fix how we set implicit conversion kinds.

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 2 17:28:25 PDT 2016


Author: gbiv
Date: Fri Sep  2 19:28:25 2016
New Revision: 280562

URL: http://llvm.org/viewvc/llvm-project?rev=280562&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=280562&r1=280561&r2=280562&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Sep  2 19:28:25 2016
@@ -1790,10 +1790,10 @@ static bool IsStandardConversion(Sema &S
                                          /*Diagnose=*/false,
                                          /*DiagnoseCFAudited=*/false,
                                          /*ConvertRHS=*/false);
-  ImplicitConversionKind ImplicitConv;
+  ImplicitConversionKind SecondConv;
   switch (Conv) {
   case Sema::Compatible:
-    ImplicitConv = ICK_C_Only_Conversion;
+    SecondConv = ICK_C_Only_Conversion;
     break;
   // For our purposes, discarding qualifiers is just as bad as using an
   // incompatible pointer. Note that an IncompatiblePointer conversion can drop
@@ -1801,18 +1801,24 @@ static bool IsStandardConversion(Sema &S
   case Sema::CompatiblePointerDiscardsQualifiers:
   case Sema::IncompatiblePointer:
   case Sema::IncompatiblePointerSign:
-    ImplicitConv = ICK_Incompatible_Pointer_Conversion;
+    SecondConv = ICK_Incompatible_Pointer_Conversion;
     break;
   default:
     return false;
   }
 
-  SCS.setAllToTypes(ToType);
-  // We need to set all three because we want this conversion to rank terribly,
-  // and we don't know what conversions it may overlap with.
-  SCS.First = ImplicitConv;
-  SCS.Second = ImplicitConv;
-  SCS.Third = ImplicitConv;
+  // First can only be an lvalue conversion, so we pretend that this was the
+  // second conversion. First should already be valid from earlier in the
+  // function.
+  SCS.Second = SecondConv;
+  SCS.setToType(1, ToType);
+
+  // Third is Identity, because Second should rank us worse than any other
+  // conversion. This could also be ICK_Qualification, but it's simpler to just
+  // lump everything in with the second conversion, and we don't gain anything
+  // from making this ICK_Qualification.
+  SCS.Third = ICK_Identity;
+  SCS.setToType(2, ToType);
   return true;
 }
 




More information about the cfe-commits mailing list