This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix the program state in reference initialization
Needs ReviewPublic

Authored by nullptr.cpp on Jan 1 2021, 1:42 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

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.

Diff Detail

Event Timeline

nullptr.cpp requested review of this revision.Jan 1 2021, 1:42 AM
nullptr.cpp created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2021, 1:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This could use some tests. (What's observably bad about the old code's behavior? does this patch fix that behavior?)