[PATCH] D93962: [Sema] Fix the program state in reference initialization

Yang Fan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 1 01:42:31 PST 2021


nullptr.cpp created this revision.
nullptr.cpp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

According to [dcl.init.ref]p5:

> A reference to type “cv1 T1” is initialized by an expression of type “cv2 T2”
>  as follows:
>
>   — If the reference is an lvalue reference and the initializer expression
>     — is an lvalue (but is not a bit-field), and “cv1 T1” is
>       reference-compatible with “cv2 T2”, or
>     — has a class type (i.e., T2 is a class type), where T1 is not
>       reference-related to T2, and can be converted to an lvalue of type
>       “cv3 T3”, where “cv1 T1” is reference-compatible with “cv3 T3” (this
>       conversion is selected by enumerating the applicable conversion functions
>       and choosing the best one through overload resolution),
>     then the reference is bound to the initializer expression lvalue in the
>     first case and to the lvalue result of the conversion in the second case
>     (or, in either case, to the appropriate base class subobject of the object).
>   
>   — Otherwise, [...]

If the overload resolution fails in the second case, the program should continue
to check other conditions and the program is NOT ill-formed at this point. But
the code here sets the program to ill-formed state.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93962

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4811,10 +4811,6 @@
             /*IsLValueRef*/ isLValueRef, Sequence);
         if (ConvOvlResult == OR_Success)
           return;
-        if (ConvOvlResult != OR_No_Viable_Function)
-          Sequence.SetOverloadFailure(
-              InitializationSequence::FK_ReferenceInitOverloadFailed,
-              ConvOvlResult);
       } else {
         ConvOvlResult = OR_No_Viable_Function;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93962.314213.patch
Type: text/x-patch
Size: 572 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210101/f113795f/attachment.bin>


More information about the cfe-commits mailing list