fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
19.84k stars 2.42k forks source link

g++-14 compilation error using named arguments inside a generic lambda #3953

Closed andrewcorrigan closed 1 month ago

andrewcorrigan commented 1 month ago

Reproducer: https://godbolt.org/z/oachhYKcT

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

Is this a GCC bug or a fmtlib bug?

vitaut commented 1 month ago

Looks like a compiler bug to me and it compiles on an earlier gcc version: https://godbolt.org/z/K1on3vYnf. Please report to gcc devs.

andrewcorrigan commented 1 month ago

reported here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114994