This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53223] New: [c++0x] auto&& and operator* don't mix inside templates
- From: "luto at mit dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 May 2012 23:09:19 +0000
- Subject: [Bug c++/53223] New: [c++0x] auto&& and operator* don't mix inside templates
- Auto-submitted: auto-generated
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.