llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] Fix incorrectly places missing 'const' in defaulted member operator overload

Open gitdode opened this issue 8 months ago • 2 comments

For a defaulted member operator overload that is not const-qualified:

std::partial_ordering operator<=>(const Box& other) = default;

clang fixes it by inserting 'const' in the wrong position, at the end instead of after the argument list:

std::partial_ordering operator<=>(const Box& other const) = default;

Simple reproducer: Box.cpp

Building with clang -Xclang -fixit <other args> reproduces the issue.

This is with:

Debian clang version 21.1.8 (3+b1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin

Please see also: https://github.com/clangd/clangd/issues/2625#issuecomment-4104351161

gitdode avatar Mar 21 '26 21:03 gitdode

For convenience, here is a slightly simplified version of the reproducer:

#include <compare>
struct Box {
    std::partial_ordering operator<=>(const Box& other) = default;
    int size;
};

Running clang-22 -std=c++23 -Xclang -fixit test.cpp on this produces the incorrect result from the issue description.

(Occurs with trunk as well.)

HighCommander4 avatar Mar 21 '26 21:03 HighCommander4

I would like to work on this!

NeKon69 avatar Mar 23 '26 17:03 NeKon69