[Bug c++/53223] New: [c++0x] auto&& and operator* don't mix inside templates
luto at mit dot edu
gcc-bugzilla@gcc.gnu.org
Thu May 3 23:09:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53223
Bug #: 53223
Summary: [c++0x] auto&& and operator* don't mix inside
templates
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: luto@mit.edu
This is truly bizarre:
struct A
{
int good() const;
int operator *() const;
};
template<typename T>
void func(T t)
{
A x;
auto &&g1 = x.good(); // OK
auto &&g2 = x.operator*(); // OK
auto &&error = *x; // error here
}
void func2(int)
{
A x;
auto &&g = *x; // OK
}
int main()
{
func(0);
func2(0);
}
gcc 4.6 and 4.7 can't compile the line marked "error here". The error looks
like:
auto-rvalue.cc: In instantiation of ‘void func(T) [with T = int]’:
auto-rvalue.cc:24:9: required from here
auto-rvalue.cc:13:19: error: invalid initialization of non-const reference of
type ‘int&’ from an rvalue of type ‘int’
I suppose this could be correct, but I'd be very surprised. clang++ 2.9
accepts this code.
More information about the Gcc-bugs
mailing list