Title
Should use of a variable in its own initializer require a diagnostic?
Status
nad
Section
9.3.4.3 [dcl.ref]
Submitter
Bjarne Stroustrup

Created on 2005-04-14.00:00:00 last changed 11 months ago

Messages

Date: 2023-05-12.20:59:33

Rationale (2023-05-12)

This is an extension whose detailed specification requires a paper targeted at EWG. Some implementations warn about the situation in question.

Date: 2006-02-15.00:00:00

Note (February, 2006):

Recent discussions have suggested that undefined behavior be reduced. One possibility (broadening the scope of this issue to include object declarations as well as references) was to require a diagnostic if the initializer uses the value, but not just the address, of the object or reference being declared:

    int i = i;        // Ill-formed, diagnostic required
    void* p = &p;     // Okay
Date: 2005-10-15.00:00:00

Rationale (October, 2005):

The CWG felt that this error was not likely to arise very often in practice. Implementations can warn about such constructs, and the resolution for issue 453 makes executing such code undefined behavior; that seemed to address the situation adequately.

Date: 2022-11-20.07:54:16

Split off from issue 453.

It is in general not possible to determine at compile time whether a reference is used before it is initialized. Nevertheless, there is some sentiment to require a diagnostic in the obvious cases that can be detected at compile time, such as the name of a reference appearing in its own initializer. The resolution of issue 453 originally made such uses ill-formed, but the CWG decided that this question should be a separate issue.

History
Date User Action Args
2023-05-12 20:59:33adminsetmessages: + msg7282
2023-05-12 20:59:33adminsetstatus: open -> nad
2006-02-24 00:00:00adminsetmessages: + msg1314
2006-02-24 00:00:00adminsetstatus: nad -> open
2005-10-22 00:00:00adminsetmessages: + msg1289
2005-10-22 00:00:00adminsetstatus: open -> nad
2005-04-14 00:00:00admincreate