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!

Reply via email to