public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error
@ 2024-04-02 10:06 Liam.Jackson@qa-systems.com
2024-04-02 11:08 ` [Bug c++/114561] " redi at gcc dot gnu.org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: Liam.Jackson@qa-systems.com @ 2024-04-02 10:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
Bug ID: 114561
Summary: Comma operator with forwarding reference to pointer
raises invalid lvalue required error
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Liam.Jackson@qa-systems.com
Target Milestone: ---
Created attachment 57845
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57845&action=edit
Source to reproduce bug
Compiling the attached source (cut down example) with `g++ -c fail.cpp` raises
the following error:
fail.cpp: In instantiation of ‘static T Create<T>::create(U&&) [with U = void*
const&; T = MyClass]’:
fail.cpp:38:28: required from here
fail.cpp:31:12: error: lvalue required as unary ‘&’ operand
31 | return T( ( (beforeParam()), (forward<U>(u)) ) );
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This code is expected to compile correctly. There is no unary '&' operator in
use.
This seems to be caused by a combination of using the comma operator and
calling `create` with a pointer variable (using nullptr directly compiles, as
shown in the code comment).
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] Comma operator with forwarding reference to pointer raises invalid lvalue required error
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
@ 2024-04-02 11:08 ` redi at gcc dot gnu.org
2024-04-02 11:28 ` redi at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-02 11:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-04-02
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=70822
Keywords| |rejects-valid
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang and EDG accept the code.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] Comma operator with forwarding reference to pointer raises invalid lvalue required error
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
2024-04-02 11:08 ` [Bug c++/114561] " redi at gcc dot gnu.org
@ 2024-04-02 11:28 ` redi at gcc dot gnu.org
2024-04-02 11:33 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-02 11:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:
void* const NONE = nullptr; //Compiles
void beforeParam();
template<typename U>
void create(U && u) noexcept {
const void* const& r = ( (void) beforeParam(), u );
}
void test_func() {
create(NONE);
}
comma.cc: In instantiation of ‘void create(U&&) [with U = void* const&]’:
comma.cc:11:11: required from here
comma.cc:7:24: error: lvalue required as unary ‘&’ operand
7 | const void* const& r = ( (void) beforeParam(), u );
| ^
GCC has recurring problems with parentheses causing lvalue expressions to be
incorrectly treated as rvalues.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] Comma operator with forwarding reference to pointer raises invalid lvalue required error
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
2024-04-02 11:08 ` [Bug c++/114561] " redi at gcc dot gnu.org
2024-04-02 11:28 ` redi at gcc dot gnu.org
@ 2024-04-02 11:33 ` redi at gcc dot gnu.org
2024-04-02 11:35 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-02 11:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Further reduced:
void create(void* u) {
const void* const& r = ( (void)0, u );
}
void test_func() {
create(0);
}
The result of (0, u) is an lvalue of type void* which should then be converted
to a const void* prvalue, which is then bound to the reference.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] Comma operator with forwarding reference to pointer raises invalid lvalue required error
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (2 preceding siblings ...)
2024-04-02 11:33 ` redi at gcc dot gnu.org
@ 2024-04-02 11:35 ` redi at gcc dot gnu.org
2024-04-02 14:38 ` [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410 jakub at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-02 11:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> Further reduced:
Actually now that it's no longer a function template we don't even need to
instantiate it to trigger the error, so this is the minimal reproducer:
void create(void* u) {
const void* const& r = ( (void)0, u );
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (3 preceding siblings ...)
2024-04-02 11:35 ` redi at gcc dot gnu.org
@ 2024-04-02 14:38 ` jakub at gcc dot gnu.org
2024-04-02 14:38 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-02 14:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Comma operator with |[11/12/13/14 Regression]
|forwarding reference to |Comma operator with
|pointer raises invalid |forwarding reference to
|lvalue required error |pointer raises invalid
| |lvalue required error since
| |r10-7410
CC| |jakub at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r10-7410-g72809d6fe8e085440403ce125c51d01d6e7512b0 too.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (4 preceding siblings ...)
2024-04-02 14:38 ` [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410 jakub at gcc dot gnu.org
@ 2024-04-02 14:38 ` jakub at gcc dot gnu.org
2024-04-02 14:45 ` jason at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-02 14:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.5
Priority|P3 |P2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (5 preceding siblings ...)
2024-04-02 14:38 ` jakub at gcc dot gnu.org
@ 2024-04-02 14:45 ` jason at gcc dot gnu.org
2024-04-02 18:11 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2024-04-02 14:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Status|NEW |ASSIGNED
CC| |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (6 preceding siblings ...)
2024-04-02 14:45 ` jason at gcc dot gnu.org
@ 2024-04-02 18:11 ` cvs-commit at gcc dot gnu.org
2024-05-01 20:31 ` [Bug c++/114561] [11/12/13 " cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-02 18:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:5d7e9a35024f065b25f61747859c7cb7a770c92b
commit r14-9757-g5d7e9a35024f065b25f61747859c7cb7a770c92b
Author: Jason Merrill <jason@redhat.com>
Date: Tue Apr 2 10:52:28 2024 -0400
c++: binding reference to comma expr [PR114561]
We represent a reference binding where the referent type is more qualified
by a ck_ref_bind around a ck_qual. We performed the ck_qual and then tried
to undo it with STRIP_NOPS, but that doesn't work if the conversion is
buried in COMPOUND_EXPR. So instead let's avoid performing that fake
conversion in the first place.
PR c++/114561
PR c++/114562
gcc/cp/ChangeLog:
* call.cc (convert_like_internal): Avoid adding qualification
conversion in direct reference binding.
gcc/testsuite/ChangeLog:
* g++.dg/conversion/ref10.C: New test.
* g++.dg/conversion/ref11.C: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12/13 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (7 preceding siblings ...)
2024-04-02 18:11 ` cvs-commit at gcc dot gnu.org
@ 2024-05-01 20:31 ` cvs-commit at gcc dot gnu.org
2024-05-24 13:26 ` [Bug c++/114561] [11/12 " cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-01 20:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:7bc362ea61e5bf552356aa862beb7845fe50a47c
commit r13-8668-g7bc362ea61e5bf552356aa862beb7845fe50a47c
Author: Jason Merrill <jason@redhat.com>
Date: Tue Apr 2 10:52:28 2024 -0400
c++: binding reference to comma expr [PR114561]
We represent a reference binding where the referent type is more qualified
by a ck_ref_bind around a ck_qual. We performed the ck_qual and then tried
to undo it with STRIP_NOPS, but that doesn't work if the conversion is
buried in COMPOUND_EXPR. So instead let's avoid performing that fake
conversion in the first place.
PR c++/114561
PR c++/114562
gcc/cp/ChangeLog:
* call.cc (convert_like_internal): Avoid adding qualification
conversion in direct reference binding.
gcc/testsuite/ChangeLog:
* g++.dg/conversion/ref10.C: New test.
* g++.dg/conversion/ref11.C: New test.
(cherry picked from commit 5d7e9a35024f065b25f61747859c7cb7a770c92b)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (8 preceding siblings ...)
2024-05-01 20:31 ` [Bug c++/114561] [11/12/13 " cvs-commit at gcc dot gnu.org
@ 2024-05-24 13:26 ` cvs-commit at gcc dot gnu.org
2024-05-24 13:27 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-24 13:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:7076c565e22281e193aeafafbf40676426a64b75
commit r12-10466-g7076c565e22281e193aeafafbf40676426a64b75
Author: Jason Merrill <jason@redhat.com>
Date: Tue Apr 2 10:52:28 2024 -0400
c++: binding reference to comma expr [PR114561]
We represent a reference binding where the referent type is more qualified
by a ck_ref_bind around a ck_qual. We performed the ck_qual and then tried
to undo it with STRIP_NOPS, but that doesn't work if the conversion is
buried in COMPOUND_EXPR. So instead let's avoid performing that fake
conversion in the first place.
PR c++/114561
PR c++/114562
gcc/cp/ChangeLog:
* call.cc (convert_like_internal): Avoid adding qualification
conversion in direct reference binding.
gcc/testsuite/ChangeLog:
* g++.dg/conversion/ref10.C: New test.
* g++.dg/conversion/ref11.C: New test.
(cherry picked from commit 5d7e9a35024f065b25f61747859c7cb7a770c92b)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (9 preceding siblings ...)
2024-05-24 13:26 ` [Bug c++/114561] [11/12 " cvs-commit at gcc dot gnu.org
@ 2024-05-24 13:27 ` cvs-commit at gcc dot gnu.org
2024-05-24 13:29 ` jason at gcc dot gnu.org
2024-05-24 13:42 ` Liam.Jackson@qa-systems.com
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-24 13:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:b35afe75674ff9f79cf9685d099bc80f10442216
commit r11-11446-gb35afe75674ff9f79cf9685d099bc80f10442216
Author: Jason Merrill <jason@redhat.com>
Date: Tue Apr 2 10:52:28 2024 -0400
c++: binding reference to comma expr [PR114561]
We represent a reference binding where the referent type is more qualified
by a ck_ref_bind around a ck_qual. We performed the ck_qual and then tried
to undo it with STRIP_NOPS, but that doesn't work if the conversion is
buried in COMPOUND_EXPR. So instead let's avoid performing that fake
conversion in the first place.
PR c++/114561
PR c++/114562
gcc/cp/ChangeLog:
* call.c (convert_like_internal): Avoid adding qualification
conversion in direct reference binding.
gcc/testsuite/ChangeLog:
* g++.dg/conversion/ref10.C: New test.
* g++.dg/conversion/ref11.C: New test.
(cherry picked from commit 5d7e9a35024f065b25f61747859c7cb7a770c92b)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (10 preceding siblings ...)
2024-05-24 13:27 ` cvs-commit at gcc dot gnu.org
@ 2024-05-24 13:29 ` jason at gcc dot gnu.org
2024-05-24 13:42 ` Liam.Jackson@qa-systems.com
12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2024-05-24 13:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed in 11.5/12.4/13.3/14.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/114561] [11/12 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
` (11 preceding siblings ...)
2024-05-24 13:29 ` jason at gcc dot gnu.org
@ 2024-05-24 13:42 ` Liam.Jackson@qa-systems.com
12 siblings, 0 replies; 14+ messages in thread
From: Liam.Jackson@qa-systems.com @ 2024-05-24 13:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114561
--- Comment #11 from Liam Jackson <Liam.Jackson@qa-systems.com> ---
Thank-you all for narrowing down and fixing this issue, and back-porting the
fix to older compilers. It is much appreciated.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-05-24 13:42 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02 10:06 [Bug c++/114561] New: Comma operator with forwarding reference to pointer raises invalid lvalue required error Liam.Jackson@qa-systems.com
2024-04-02 11:08 ` [Bug c++/114561] " redi at gcc dot gnu.org
2024-04-02 11:28 ` redi at gcc dot gnu.org
2024-04-02 11:33 ` redi at gcc dot gnu.org
2024-04-02 11:35 ` redi at gcc dot gnu.org
2024-04-02 14:38 ` [Bug c++/114561] [11/12/13/14 Regression] Comma operator with forwarding reference to pointer raises invalid lvalue required error since r10-7410 jakub at gcc dot gnu.org
2024-04-02 14:38 ` jakub at gcc dot gnu.org
2024-04-02 14:45 ` jason at gcc dot gnu.org
2024-04-02 18:11 ` cvs-commit at gcc dot gnu.org
2024-05-01 20:31 ` [Bug c++/114561] [11/12/13 " cvs-commit at gcc dot gnu.org
2024-05-24 13:26 ` [Bug c++/114561] [11/12 " cvs-commit at gcc dot gnu.org
2024-05-24 13:27 ` cvs-commit at gcc dot gnu.org
2024-05-24 13:29 ` jason at gcc dot gnu.org
2024-05-24 13:42 ` Liam.Jackson@qa-systems.com
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).