public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1
@ 2024-05-08 19:47 andrew.corrigan at gmail dot com
2024-05-08 20:02 ` [Bug c++/114994] " mpolacek at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: andrew.corrigan at gmail dot com @ 2024-05-08 19:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
Bug ID: 114994
Summary: fmtlib named argument compiler error introduced in
g++-14.1
Product: gcc
Version: 14.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: andrew.corrigan at gmail dot com
Target Milestone: ---
Demo: https://godbolt.org/z/oachhYKcT
First reported to https://github.com/fmtlib/fmt/issues/3953. The fmtlib author
believes the error below is a compiler bug. Using fmtlib's named arguments
inside a generic lambda stopped working as of g++-14.1. The reproducer below
compiles on every other compiler I've tried (earlier versions of g++, clang++,
intel, and msvc)
```
#include <iostream>
#define FMT_HEADER_ONLY
#include <fmt/format.h>
using namespace fmt::literals;
int main()
{
auto test = [&](auto a)
{
return fmt::format("{foo} {bar}", "foo"_a="foo", "bar"_a="bar");
};
std::cout << test(1) << std::endl;
return 0;
}
```
Error:
```
<source>:12:50: error: cannot bind non-const lvalue reference of type
'fmt::v10::detail::named_arg<char, const char (&)[4]>&' to an rvalue of type
'fmt::v10::detail::named_arg<char, const char (&)[4]>'
12 | return fmt::format("{foo} {bar}", "foo"_a="foo",
"bar"_a="bar");
| ~~~~~~~^~~~~~
```
Changing `auto a` to `int a` works around the error.
Thank you!
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
@ 2024-05-08 20:02 ` mpolacek at gcc dot gnu.org
2024-05-08 20:04 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-05-08 20:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |needs-reduction
CC| |mpolacek at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looks like it started with r14-4111:
commit 6e92a6a2a72d3b7a5e1b29042d8a6a43fe1085aa
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Sep 18 14:47:52 2023 -0400
c++: non-dependent assignment checking [PR63198, PR18474]
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
2024-05-08 20:02 ` [Bug c++/114994] " mpolacek at gcc dot gnu.org
@ 2024-05-08 20:04 ` pinskia at gcc dot gnu.org
2024-05-08 20:16 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-08 20:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note lambdas is not need can happen in any template function:
```
#include <iostream>
#define FMT_HEADER_ONLY
#include <fmt/format.h>
using namespace fmt::literals;
template<int T>
auto test(int a)
{
return fmt::format("{foo} {bar}", "foo"_a="foo", "bar"_a="bar");
}
auto t = test<1>(1);
```
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
2024-05-08 20:02 ` [Bug c++/114994] " mpolacek at gcc dot gnu.org
2024-05-08 20:04 ` pinskia at gcc dot gnu.org
@ 2024-05-08 20:16 ` pinskia at gcc dot gnu.org
2024-05-08 21:40 ` [Bug c++/114994] [14/15 Regression] " pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-08 20:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Trying my hand at reducing this slightly.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] [14/15 Regression] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
` (2 preceding siblings ...)
2024-05-08 20:16 ` pinskia at gcc dot gnu.org
@ 2024-05-08 21:40 ` pinskia at gcc dot gnu.org
2024-05-08 22:23 ` ppalka at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-08 21:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|fmtlib named argument |[14/15 Regression] fmtlib
|compiler error introduced |named argument compiler
|in g++-14.1 |error introduced in
| |g++-14.1
Target Milestone|--- |14.2
Ever confirmed|0 |1
Keywords|needs-reduction |rejects-valid
Last reconfirmed| |2024-05-08
Status|UNCONFIRMED |NEW
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
typedef decltype(sizeof(1)) size_t;
struct udl_arg {
const char *str;
template <typename T> auto operator=(T &&value) const -> int {}
};
constexpr auto operator""_a(const char *s, size_t) -> udl_arg
{
return {""};
}
template <typename T> void h(T &&);
template<int T>
int test(int a)
{
h("t"_a="t");
}
auto t = test<1>(1);
````
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] [14/15 Regression] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
` (3 preceding siblings ...)
2024-05-08 21:40 ` [Bug c++/114994] [14/15 Regression] " pinskia at gcc dot gnu.org
@ 2024-05-08 22:23 ` ppalka at gcc dot gnu.org
2024-05-10 8:06 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-05-08 22:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
A bit more reduced, demostrating it's not specific to UDLs:
struct udl_arg {
udl_arg operator=(int);
};
void g(udl_arg&&);
template<class T>
void h() {
udl_arg x;
g(x=42);
}
int main() {
h<int>();
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] [14/15 Regression] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
` (4 preceding siblings ...)
2024-05-08 22:23 ` ppalka at gcc dot gnu.org
@ 2024-05-10 8:06 ` rguenth at gcc dot gnu.org
2024-05-15 2:56 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-10 8:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
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++/114994] [14/15 Regression] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
` (5 preceding siblings ...)
2024-05-10 8:06 ` rguenth at gcc dot gnu.org
@ 2024-05-15 2:56 ` cvs-commit at gcc dot gnu.org
2024-05-20 13:51 ` cvs-commit at gcc dot gnu.org
2024-05-20 13:52 ` ppalka at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-15 2:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:c6cc6d4741a880109c4e0e64d5a189687fb526f6
commit r15-498-gc6cc6d4741a880109c4e0e64d5a189687fb526f6
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue May 14 22:55:16 2024 -0400
c++: lvalueness of non-dependent assignment expr [PR114994]
r14-4111-g6e92a6a2a72d3b made us check non-dependent simple assignment
expressions ahead of time and give them a type, as was already done for
compound assignments. Unlike for compound assignments however, if a
simple assignment resolves to an operator overload we represent it as a
(typed) MODOP_EXPR instead of a CALL_EXPR to the selected overload.
(I reckoned this was at worst a pessimization -- we'll just have to repeat
overload resolution at instantiatiation time.)
But this turns out to break the below testcase ultimately because
MODOP_EXPR (of non-reference type) is always treated as an lvalue
according to lvalue_kind, which is incorrect for the MODOP_EXPR
representing x=42.
We can fix this by representing such class assignment expressions as
CALL_EXPRs as well, but this turns out to require some tweaking of our
-Wparentheses warning logic and may introduce other fallout making it
unsuitable for backporting.
So this patch instead fixes lvalue_kind to consider the type of a
MODOP_EXPR representing a class assignment.
PR c++/114994
gcc/cp/ChangeLog:
* tree.cc (lvalue_kind) <case MODOP_EXPR>: For a class
assignment, consider the result type.
gcc/testsuite/ChangeLog:
* g++.dg/template/non-dependent32.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] [14/15 Regression] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
` (6 preceding siblings ...)
2024-05-15 2:56 ` cvs-commit at gcc dot gnu.org
@ 2024-05-20 13:51 ` cvs-commit at gcc dot gnu.org
2024-05-20 13:52 ` ppalka at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-20 13:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:b3399b445ba7495b0479d43f2389e64d48de870e
commit r14-10220-gb3399b445ba7495b0479d43f2389e64d48de870e
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue May 14 22:55:16 2024 -0400
c++: lvalueness of non-dependent assignment expr [PR114994]
r14-4111-g6e92a6a2a72d3b made us check non-dependent simple assignment
expressions ahead of time and give them a type, as was already done for
compound assignments. Unlike for compound assignments however, if a
simple assignment resolves to an operator overload we represent it as a
(typed) MODOP_EXPR instead of a CALL_EXPR to the selected overload.
(I reckoned this was at worst a pessimization -- we'll just have to repeat
overload resolution at instantiatiation time.)
But this turns out to break the below testcase ultimately because
MODOP_EXPR (of non-reference type) is always treated as an lvalue
according to lvalue_kind, which is incorrect for the MODOP_EXPR
representing x=42.
We can fix this by representing such class assignment expressions as
CALL_EXPRs as well, but this turns out to require some tweaking of our
-Wparentheses warning logic and may introduce other fallout making it
unsuitable for backporting.
So this patch instead fixes lvalue_kind to consider the type of a
MODOP_EXPR representing a class assignment.
PR c++/114994
gcc/cp/ChangeLog:
* tree.cc (lvalue_kind) <case MODOP_EXPR>: For a class
assignment, consider the result type.
gcc/testsuite/ChangeLog:
* g++.dg/template/non-dependent32.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit c6cc6d4741a880109c4e0e64d5a189687fb526f6)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/114994] [14/15 Regression] fmtlib named argument compiler error introduced in g++-14.1
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
` (7 preceding siblings ...)
2024-05-20 13:51 ` cvs-commit at gcc dot gnu.org
@ 2024-05-20 13:52 ` ppalka at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-05-20 13:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #8 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14.2, thanks for the bug report.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-05-20 13:52 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 19:47 [Bug c++/114994] New: fmtlib named argument compiler error introduced in g++-14.1 andrew.corrigan at gmail dot com
2024-05-08 20:02 ` [Bug c++/114994] " mpolacek at gcc dot gnu.org
2024-05-08 20:04 ` pinskia at gcc dot gnu.org
2024-05-08 20:16 ` pinskia at gcc dot gnu.org
2024-05-08 21:40 ` [Bug c++/114994] [14/15 Regression] " pinskia at gcc dot gnu.org
2024-05-08 22:23 ` ppalka at gcc dot gnu.org
2024-05-10 8:06 ` rguenth at gcc dot gnu.org
2024-05-15 2:56 ` cvs-commit at gcc dot gnu.org
2024-05-20 13:51 ` cvs-commit at gcc dot gnu.org
2024-05-20 13:52 ` ppalka 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).