c++/2112: Diagnostic message misleading for binding r-value to non-const reference

richarda@ixla.com.au richarda@ixla.com.au
Mon Feb 26 19:16:00 GMT 2001


>Number:         2112
>Category:       c++
>Synopsis:       Diagnostic message misleading for binding r-value to non-const reference
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 26 19:16:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Richard Andrews, Ixla Ltd.
>Release:        CVS 20010215
>Organization:
>Environment:
i386-pc-linux-gnu (RedHat 6.2)
>Description:
When a function (particularly constructor) takes a 
non-const reference argument and a temporary is passed 
to it, the compiler generates a diagnostic that the 
function signature does not match any prototype.

This is misleading. The problem is that a temporary is being 
pass as a non-const reference.

It took me hours to figure the real problem and I consider 
my an experienced C++ user.
>How-To-Repeat:

//compile this

struct item
{
    item(int i);

    int it_;
};

struct thing
{
    thing( item & it );

    int th_;
};

void doTest()
{
//    item i(0);
//    thing th( i );

    thing th( item(1) ); // passes temporary to constructor
}
>Fix:
Produce correct diagnostic.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list