https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119191
Bug ID: 119191
Summary: Add fix-it for missing argument list in operator()
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
struct A {
void operator();
void operator(int);
};
struct B {
void operator() { }
void operator(int) { }
};
struct C {
void operator() const;
void operator(int) const;
};
These are all invalid declarations, they should be operator()() or
operator()(int).
The diagnostics are not very clear though:
callop.cc:2:8: error: declaration of ‘operator()’ as non-function
2 | void operator();
| ^~~~~~~~
callop.cc:3:16: error: expected type-specifier before ‘(’ token
3 | void operator(int, int);
| ^
callop.cc:7:8: error: declaration of ‘operator()’ as non-function
7 | void operator() { }
| ^~~~~~~~
callop.cc:7:21: error: expected ‘;’ at end of member declaration
7 | void operator() { }
| ^
| ;
callop.cc:8:16: error: expected type-specifier before ‘(’ token
8 | void operator(int, int) { }
| ^
callop.cc:12:8: error: declaration of ‘operator()’ as non-function
12 | void operator() const;
| ^~~~~~~~
callop.cc:12:17: error: expected ‘;’ at end of member declaration
12 | void operator() const;
| ^
| ;
callop.cc:12:19: error: declaration does not declare anything [-fpermissive]
12 | void operator() const;
| ^~~~~
callop.cc:13:16: error: expected type-specifier before ‘(’ token
13 | void operator(int, int) const;
| ^
It would be nice if we added a fix-it suggesting to add `()' after `operator'