c++/6507: auto type promotion of referee in reference member variable initialization

stephen.hill@motorola.com stephen.hill@motorola.com
Mon Apr 29 10:09:00 GMT 2002


>Number:         6507
>Category:       c++
>Synopsis:       auto type promotion of referee in reference member variable initialization
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 29 08:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     stephen.hill@motorola.com
>Release:        gcc 2.95.2 19991024 (release)
>Organization:
>Environment:
Linux x86 (suse 7.0 default install)
>Description:
Note: I'm not sure if this really is a bug (or just a feature), but it strikes me that the code is doing something so different from a reasonable expectation that a closer examination of the reasoning might be desirable.

When initializing a reference member variable of a class, it appears that gcc attempts do do a type promotion of the referee into the reference class, then references the promoted variable.

In the attached code, note the difference between reference and referee addresses.If the constructor (lines 19-22) is replaced by a constructor which does not take an argument of the reference type (lines 24-27) an error is generated. This makes me believe that automatic type promotion is involved.

Note that if b (line 38) is declared as
   const explicit Foo &b;
rather than
   const Foo &b 
then no problem results.

Thanks,
steve
>How-To-Repeat:
compile attached file (gcc -o bug_test bug_test.cc)
run (./bug_test)
>Fix:
Assume that member references to member variables are explicit or warn?
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list