public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103403] New: Decltype of rvalue reference
@ 2021-11-24 9:38 enricomaria.dean6elis at gmail dot com
2021-11-24 9:50 ` [Bug c++/103403] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: enricomaria.dean6elis at gmail dot com @ 2021-11-24 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Bug ID: 103403
Summary: Decltype of rvalue reference
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: enricomaria.dean6elis at gmail dot com
CC: anders.granlund.0 at gmail dot com,
daniel.kruegler at googlemail dot com, jason at gcc dot gnu.org,
mpolacek at gcc dot gnu.org, trippels at gcc dot gnu.org,
webrown.cpp at gmail dot com
Target Milestone: ---
Unlike the comment at the end of the original report claims, the bug seems to
be still present (or at least a different shade of it).
StackOverflow question:
https://stackoverflow.com/questions/70092776/validity-of-presenting-an-xvalue-as-an-lvalue
Repro: https://godbolt.org/z/h943G933a
+++ This bug was initially created as a clone of Bug #78209 +++
This came up on the isocpp mailing list yesterday:
markus@x4 /tmp % cat test.ii
int main() {
int &&i = 0;
decltype(auto) j = i;
return j;
}
markus@x4 /tmp % clang++ test.ii
test.ii:3:18: error: rvalue reference to type 'int' cannot bind to lvalue of
type 'int'
decltype(auto) j = i;
^ ~
1 error generated.
markus@x4 /tmp % icpc test.ii
test.ii(3): error: an rvalue reference cannot be bound to an lvalue
decltype(auto) j = i;
^
compilation aborted for test.ii (code 2)
markus@x4 /tmp % g++ -Wall -Wextra test.ii
markus@x4 /tmp %
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] Decltype of rvalue reference
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
@ 2021-11-24 9:50 ` pinskia at gcc dot gnu.org
2021-11-24 9:59 ` [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24 9:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is a totally different issue and unrelated issue from PR 78209
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
2021-11-24 9:50 ` [Bug c++/103403] " pinskia at gcc dot gnu.org
@ 2021-11-24 9:59 ` pinskia at gcc dot gnu.org
2021-11-24 10:09 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24 9:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.3
Ever confirmed|0 |1
Known to fail| |11.1.0
Summary|Decltype of rvalue |[11/12 Regression] auto
|reference |return type with a trailing
| |return type of decl(auto)
| |uses rvalue reference type
| |instead of reference type
Status|UNCONFIRMED |NEW
Known to work| |10.1.0, 10.3.0, 7.1.0
Last reconfirmed| |2021-11-24
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a C++14 testcase which shows this is also a regression:
template<typename T>
auto constexpr RtoL1(T&& r) -> decltype(auto) {
return (r);
};
int main() {
int t;
int x{3};
decltype (RtoL1(x+0)) y = t;
}
Confirmed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
2021-11-24 9:50 ` [Bug c++/103403] " pinskia at gcc dot gnu.org
2021-11-24 9:59 ` [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type pinskia at gcc dot gnu.org
@ 2021-11-24 10:09 ` rguenth at gcc dot gnu.org
2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-24 10:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
` (2 preceding siblings ...)
2021-11-24 10:09 ` rguenth at gcc dot gnu.org
@ 2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
2021-11-24 15:07 ` enricomaria.dean6elis at gmail dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-24 14:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with my r11-4758, sigh.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
` (3 preceding siblings ...)
2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
@ 2021-11-24 15:07 ` enricomaria.dean6elis at gmail dot com
2021-12-03 19:00 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: enricomaria.dean6elis at gmail dot com @ 2021-11-24 15:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
--- Comment #4 from Enrico Maria De Angelis <enricomaria.dean6elis at gmail dot com> ---
So there is a relation between this problem and PR 78209. At least a
cause-effect relation.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
` (4 preceding siblings ...)
2021-11-24 15:07 ` enricomaria.dean6elis at gmail dot com
@ 2021-12-03 19:00 ` cvs-commit at gcc dot gnu.org
2021-12-03 19:01 ` [Bug c++/103403] [11 " mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-03 19:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:abd7712f91c99690f8b0046ea168b2782afbac69
commit r12-5778-gabd7712f91c99690f8b0046ea168b2782afbac69
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Nov 30 21:07:25 2021 -0500
c++: Fix for decltype(auto) and parenthesized expr [PR103403]
In r11-4758, I tried to fix this problem:
int &&i = 0;
decltype(auto) j = i; // should behave like int &&j = i; error
wherein do_auto_deduction was getting confused with a REFERENCE_REF_P
and it didn't realize its operand was a name, not an expression, and
deduced the wrong type.
Unfortunately that fix broke this:
int&& r = 1;
decltype(auto) rr = (r);
where 'rr' should be 'int &' since '(r)' is an expression, not a name. But
because I stripped the INDIRECT_REF with the r11-4758 change, we deduced
'rr's type as if decltype had gotten a name, resulting in 'int &&'.
I suspect I thought that the REF_PARENTHESIZED_P check when setting
'bool id' in do_auto_deduction would handle the (r) case, but that's not
the case; while the documentation for REF_PARENTHESIZED_P specifically says
it can be set in INDIRECT_REF, we don't actually do so.
This patch sets REF_PARENTHESIZED_P even on REFERENCE_REF_P, so that
do_auto_deduction can use it.
It also removes code in maybe_undo_parenthesized_ref that I think is
dead -- and we don't hit it while running dg.exp. To adduce more data,
it also looks dead here:
https://splichal.eu/lcov/gcc/cp/semantics.c.gcov.html
(It's dead since r9-1417.)
Also add a fixed test for c++/81176.
PR c++/103403
gcc/cp/ChangeLog:
* cp-gimplify.c (cp_fold): Don't recurse if
maybe_undo_parenthesized_ref
doesn't change its argument.
* pt.c (do_auto_deduction): Don't strip REFERENCE_REF_P trees if
they
are REF_PARENTHESIZED_P. Use stripped_init when checking for
id-expression.
* semantics.c (force_paren_expr): Set REF_PARENTHESIZED_P on
REFERENCE_REF_P trees too.
(maybe_undo_parenthesized_ref): Remove dead code.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/decltype-auto2.C: New test.
* g++.dg/cpp1y/decltype-auto3.C: New test.
* g++.dg/cpp1y/decltype-auto4.C: New test.
* g++.dg/cpp1z/decomp-decltype1.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
` (5 preceding siblings ...)
2021-12-03 19:00 ` cvs-commit at gcc dot gnu.org
@ 2021-12-03 19:01 ` mpolacek at gcc dot gnu.org
2022-04-21 7:50 ` rguenth at gcc dot gnu.org
2023-03-07 17:46 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-12-03 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12 Regression] auto |[11 Regression] auto return
|return type with a trailing |type with a trailing return
|return type of decl(auto) |type of decl(auto) uses
|uses rvalue reference type |rvalue reference type
|instead of reference type |instead of reference type
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
` (6 preceding siblings ...)
2021-12-03 19:01 ` [Bug c++/103403] [11 " mpolacek at gcc dot gnu.org
@ 2022-04-21 7:50 ` rguenth at gcc dot gnu.org
2023-03-07 17:46 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21 7:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.3 |11.4
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103403] [11 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
` (7 preceding siblings ...)
2022-04-21 7:50 ` rguenth at gcc dot gnu.org
@ 2023-03-07 17:46 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-07 17:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103403
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-03-07 17:46 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 9:38 [Bug c++/103403] New: Decltype of rvalue reference enricomaria.dean6elis at gmail dot com
2021-11-24 9:50 ` [Bug c++/103403] " pinskia at gcc dot gnu.org
2021-11-24 9:59 ` [Bug c++/103403] [11/12 Regression] auto return type with a trailing return type of decl(auto) uses rvalue reference type instead of reference type pinskia at gcc dot gnu.org
2021-11-24 10:09 ` rguenth at gcc dot gnu.org
2021-11-24 14:37 ` mpolacek at gcc dot gnu.org
2021-11-24 15:07 ` enricomaria.dean6elis at gmail dot com
2021-12-03 19:00 ` cvs-commit at gcc dot gnu.org
2021-12-03 19:01 ` [Bug c++/103403] [11 " mpolacek at gcc dot gnu.org
2022-04-21 7:50 ` rguenth at gcc dot gnu.org
2023-03-07 17:46 ` mpolacek 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).