Title
Unclear suppression of standard conversions while binding reference to lvalue
Status
nad
Section
9.4.4 [dcl.init.ref]
Submitter
Bronek Kozicki

Created on 2003-09-14.00:00:00 last changed 238 months ago

Messages

Date: 2005-04-15.00:00:00

Rationale (April, 2005):

As acknowledged in the description of the issue, the referenced text is only a note and has no normative impact. Furthermore, the examples cited do not involve the conversions mentioned in the note, and the normative text is already sufficiently clear that the types in the examples are not reference-compatible.

Date: 2022-11-20.07:54:16

In section 9.4.4 [dcl.init.ref], paragraph 5, there is following note:

Note: the usual lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are not needed, and therefore are suppressed, when such direct bindings to lvalues are done.

I believe that this note is misleading. There should be either:

  • no note, and leave this issue to be explained in section 4 only
  • explicit list of all suppressed conversions (including pointer qualification conversion, as covered in section 4.4)
  • reminder that result of all standard conversions is never an lvalue, thus these conversions are suppressed when binding reference to lvalue

The problem:

  1. under current wording it's unclear if following code is legal, or not:
    int main()
    {
      const int ci = 10;
      int * pi = NULL;
      const int * & rpci = pi;
      rpci = &ci;
      *pi = 12; // circumvent constness of "ci"
    }
    
  2. it is also unclear what behaviour should following program expose:
    int main()
    {
      int * pi = NULL;
      const int * const & rcpci = pi; // 1
      int i = 0;
      pi = &i; // 2
      if (pi == rcpci)
        std::cout << "bound to lvalue" << std::endl;
      else
        std::cout << "bound to temporary rvalue" << std::endl;
    }
    

There has been discussion on this issue on comp.lang.c++.moderated month ago, see http://groups.google.pl/groups?threadm=9bed99bb.0308041153.1c79e882%40posting.google.com and there seems to be some confusion about it. I understand that note is not normative, but apparently even some compiler writers are misled (try above code snippets on few different compilers, and using different compilation options - notably GCC 3.2.3 with -Wall -pedantic), thus it should be cleared up.

My proposal is to change wording of discussed note to:

Note: result of every standard conversion is never an lvalue, and therefore all standard conversions (clause 4) are suppressed, when such direct bindings to lvalues are done.
History
Date User Action Args
2005-05-01 00:00:00adminsetmessages: + msg1198
2005-05-01 00:00:00adminsetstatus: drafting -> nad
2003-11-15 00:00:00adminsetstatus: open -> drafting
2003-09-14 00:00:00admincreate