public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51547] New: auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X'
@ 2011-12-14 5:17 tudorb at fb dot com
2011-12-14 12:01 ` [Bug c++/51547] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: tudorb at fb dot com @ 2011-12-14 5:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51547
Bug #: 51547
Summary: auto, type deduction, reference collapsing and const:
invalid initialization of reference of type 'const
X&&' from expression of type 'const X'
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: tudorb@fb.com
Created attachment 26074
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26074
g++ -E output
The following program fails to compile using g++ 4.6.2 (g++ -std=c++0x)
#include <vector>
struct Bar {
int x;
};
struct Foo {
const std::vector<Bar>& bar() const {
return bar_;
}
std::vector<Bar> bar_;
};
template <class X>
struct Y {
void foo() {
Foo a;
auto b = a.bar().begin();
auto&& c = b->x;
}
};
template <class X>
void foo() {
Foo a;
auto b = a.bar().begin();
auto&& c = b->x;
}
int main() {
Y<int> p;
p.foo();
foo<int>();
}
a.cpp: In member function ‘void Y<X>::foo() [with X = int]’:
a.cpp:34:9: instantiated from here
a.cpp:20:19: error: invalid initialization of reference of type ‘const int&&’
from expression of type ‘const int’
a.cpp: In function ‘void foo() [with X = int]’:
a.cpp:35:12: instantiated from here
a.cpp:28:17: error: invalid initialization of reference of type ‘const int&&’
from expression of type ‘const int’
The program compiles correctly if Y or foo() are non-templates.
Reference collapsing should deduce "auto&& c" as "const int&", and it appears
to do so in the non-template case.
Note that this bug is very brittle to reproduce (I tried to reduce it to remove
the use of std::vector, but I couldn't) -- for example, replacing "b->x" with
"(*b).x" makes the code compile correctly.
Attaching the preprocessor output (g++ -std=c++0x -E)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51547] auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X'
2011-12-14 5:17 [Bug c++/51547] New: auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X' tudorb at fb dot com
@ 2011-12-14 12:01 ` redi at gcc dot gnu.org
2011-12-27 19:08 ` paolo at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-14 12:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51547
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
CC| |jason at gcc dot gnu.org
Known to work| |4.7.0
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-14 11:34:39 UTC ---
compiles fine with 4.7.0 20111126, but I'm not sure if it's fixed or just
latent
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51547] auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X'
2011-12-14 5:17 [Bug c++/51547] New: auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X' tudorb at fb dot com
2011-12-14 12:01 ` [Bug c++/51547] " redi at gcc dot gnu.org
@ 2011-12-27 19:08 ` paolo at gcc dot gnu.org
2011-12-27 19:15 ` paolo.carlini at oracle dot com
2011-12-28 15:59 ` paolo at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: paolo at gcc dot gnu.org @ 2011-12-27 19:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51547
--- Comment #2 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2011-12-27 19:04:28 UTC ---
Author: paolo
Date: Tue Dec 27 19:04:24 2011
New Revision: 182695
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182695
Log:
2011-12-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51547
* g++.dg/cpp0x/pr51547.C: New.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/pr51547.C
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51547] auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X'
2011-12-14 5:17 [Bug c++/51547] New: auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X' tudorb at fb dot com
2011-12-14 12:01 ` [Bug c++/51547] " redi at gcc dot gnu.org
2011-12-27 19:08 ` paolo at gcc dot gnu.org
@ 2011-12-27 19:15 ` paolo.carlini at oracle dot com
2011-12-28 15:59 ` paolo at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-12-27 19:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51547
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.7.0
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-12-27 19:07:23 UTC ---
Testcase added, I'm closing the PR as fixed for 4.7.0.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51547] auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X'
2011-12-14 5:17 [Bug c++/51547] New: auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X' tudorb at fb dot com
` (2 preceding siblings ...)
2011-12-27 19:15 ` paolo.carlini at oracle dot com
@ 2011-12-28 15:59 ` paolo at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: paolo at gcc dot gnu.org @ 2011-12-28 15:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51547
--- Comment #4 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2011-12-28 15:53:01 UTC ---
Author: paolo
Date: Wed Dec 28 15:52:54 2011
New Revision: 182709
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182709
Log:
2011-12-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51547
* g++.dg/cpp0x/pr51547.C: New.
Modified:
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-12-28 15:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-14 5:17 [Bug c++/51547] New: auto, type deduction, reference collapsing and const: invalid initialization of reference of type 'const X&&' from expression of type 'const X' tudorb at fb dot com
2011-12-14 12:01 ` [Bug c++/51547] " redi at gcc dot gnu.org
2011-12-27 19:08 ` paolo at gcc dot gnu.org
2011-12-27 19:15 ` paolo.carlini at oracle dot com
2011-12-28 15:59 ` paolo at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).