https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119394

            Bug ID: 119394
           Summary: Add fixit hint suggesting adding () to [] noexcept {}
                    in C++ < 23
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

Note that clang alread does this: https://godbolt.org/z/73T38rWM7

void foo(auto){}
void test() {
    foo([] noexcept {});
}

No fixit when running `g++ -std=c++20 -Wall -Werror`:

<source>: In function 'void test()':
<source>:3:12: error: parameter declaration before lambda exception
specification only optional with '-std=c++23' or '-std=gnu++23'
[-Werror=c++23-extensions]
    3 |     foo([] noexcept {});
      |            ^~~~~~~~
cc1plus: all warnings being treated as errors

Clang20 output with fixit:

<source>:3:12: error: lambda without a parameter clause is a C++23 extension
[-Werror,-Wc++23-extensions]
    3 |     foo([] noexcept {});
      |            ^
      |            () 
1 error generated.

It might also be better to just replace the technical sounding "parameter
declaration before lambda exception specification" with just "() before
noexcept on a lambda" which I think will be easier for the mythical "normal C++
developer" to understand.
  • [Bug c++/119394] New: Add fixit... redbeard0531 at gmail dot com via Gcc-bugs

Reply via email to