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

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).