Bug 38540 - Type of 'const int f ()'
Summary: Type of 'const int f ()'
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2008-12-16 12:03 UTC by Wolfgang Roehrl
Modified: 2011-09-24 23:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.2
Known to fail: 3.3.3, 4.0.0, 4.3.0, 4.4.0
Last reconfirmed: 2008-12-23 23:24:42


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Roehrl 2008-12-16 12:03:25 UTC
Dear all,

I would like to post a fault report for the GNU C/C++ compiler 4.3.0.

Used invokation line for the GNU C++ compiler:

gcc -c -x c++ -ansi -Wall -Werror -mcpu=603e -fverbose-asm -mbig
    -mmultiple -mstring -mstrict-align -meabi -msdata -fno-common
    -fno-exceptions -fno-rtti -O3 -fno-section-anchors
    -I<different include paths>
    -D<different #define's>
    X.CPP -oX.O


// example program

const int f ();

template <typename T_>
void g (T_&);

void h (void)
{ g(f()); }


GNU accepts the code fragment above which is illegal. It is illegal because
. Function f() yields a rvalue (3.10/5);
. the type of f() is "int" and not "const int" since only a class-type
  rvalue can be const-qualified (3.10/9);
. so function g() should be instantiated as g<int>(int&) in the expression
  "g(f())";
. the parameter "int&" of function g<int>(int&) cannot bind a non-const
  rvalue (8.5.3/5).

BTW, the Comeau online compiler rejects the code above. 

Kind regards
W. Roehrl
Comment 1 Andrew Pinski 2008-12-23 23:24:42 UTC
Confirmed.  Not a regression.
Comment 2 Paolo Carlini 2011-09-24 23:19:23 UTC
Fixed long ago.