llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

Poor diagnostic quality for operators that cannot be used as fold-operator #91959

Open Eisenwave opened 4 months ago

Eisenwave commented 4 months ago
template <typename... Ts>
void awoo(Ts... args) {
    (args <=> ...);
}

For this code, clang outputs (https://godbolt.org/z/xozTW66rY):

<source>:3:15: error: expected expression
    3 |     (args <=> ...);
      |               ^

There are also less than ideal diagnostics for -> (and I assume, some other operators that cannot be folded over).

Presumably, this happens because (args <=> ...) is not parsed as a fold-expression at all, so you get some syntax error. It may be better to parse it as a fold-expression but immediately reject it with an error such as

<=> is not a fold operator.

shafik commented 4 months ago

edg is the only one to do a decent job here: https://godbolt.org/z/77anjbnh4

"<source>", line 3: error: invalid fold expression operator
      (args <=> ...);
            ^