[Bug c++/119191] Add fix-it for missing argument list in operator()

2025-03-10 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119191

--- Comment #1 from Jonathan Wakely  ---
Clang is no better, it also just says "that's wrong" without a fix-it:

callop.cc:2:8: error: 'operator()' cannot be the name of a variable or data
member
2 |   void operator();
  |^
callop.cc:3:17: error: expected ')'
3 |   void operator(int);
  | ^
callop.cc:3:16: note: to match this '('
3 |   void operator(int);
  |^
callop.cc:3:8: error: 'operator()' cannot be the name of a variable or data
member
3 |   void operator(int);
  |^
callop.cc:7:8: error: 'operator()' cannot be the name of a variable or data
member
7 |   void operator() { }
  |^
callop.cc:7:22: error: expected ';' at end of declaration list
7 |   void operator() { }
  |  ^
  |  ;
callop.cc:12:8: error: 'operator()' cannot be the name of a variable or data
member
   12 |   void operator() const;
  |^
callop.cc:12:18: error: expected ';' at end of declaration list
   12 |   void operator() const;
  |  ^
  |  ;
callop.cc:13:17: error: expected ')'
   13 |   void operator(int) const;
  | ^
callop.cc:13:16: note: to match this '('
   13 |   void operator(int) const;
  |^
callop.cc:13:8: error: 'operator()' cannot be the name of a variable or data
member
   13 |   void operator(int) const;
  |^
callop.cc:13:21: error: expected ';' at end of declaration list
   13 |   void operator(int) const;
  | ^
  | ;
10 errors generated.

[Bug c++/119191] Add fix-it for missing argument list in operator()

2025-03-10 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119191

--- Comment #3 from Jonathan Wakely  ---
The 'operator(int)' case is interesting because it could be a typo for several
other operators, operator+(int) or operator++(int) or operator[](int).

Personally, I know that I forget the double parens for operator()() or
operator()(T) a lot more often than I forget the operator symbol for operator+
or operator[]. The fact that I've typed one set of parens seems to make my
fingers and/or brain think I've got it right.

So my gut feel is that suggesting to add () would be right more often than not.
Maybe it could be phrased as "To make this a call operator, add empty
parentheses (), otherwise add another operator symbol such as +, [], or add a
type name"

[Bug c++/119191] Add fix-it for missing argument list in operator()

2025-03-10 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119191

--- Comment #4 from Jonathan Wakely  ---
(In reply to Jonathan Wakely from comment #0)
> callop.cc:3:16: error: expected type-specifier before ‘(’ token
> 3 |   void operator(int, int);
>   |^

Oops, I posted the output from testing a version of the test using
operator(int, int) instead of operator(int) but it didn't affect the
diagnostics, except for the quoted source shown in the caret diagnostic.

[Bug c++/119191] Add fix-it for missing argument list in operator()

2025-03-10 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119191

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2025-03-10
 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW

--- Comment #5 from Andrew Pinski  ---
.

[Bug c++/119191] Add fix-it for missing argument list in operator()

2025-03-10 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119191

--- Comment #2 from Jonathan Wakely  ---
EDG is almost there:

"callop.cc", line 2: error: an operator name must be declared as a function
void operator();
 ^

"callop.cc", line 3: error: expected an operator
void operator(int);
 ^

"callop.cc", line 7: error: an operator name must be declared as a function
void operator() { }
 ^

"callop.cc", line 7: error: expected a ";"
void operator() { }
^

"callop.cc", line 12: error: an operator name must be declared as a function
void operator() const;
 ^

"callop.cc", line 12: error: expected a ";"
void operator() const;
^

"callop.cc", line 13: error: expected an operator
void operator(int) const;
 ^

7 errors detected in the compilation of "callop.cc".


For the first one, "an operator name must be declared as a function" is
correctly saying that 'operator()' is an operator name, and so it must be
declared as a function, i.e. with a parameter list. That's technically correct,
and not just "that's wrong", but could use more user-friendly wording.

And for the second one, "expected an operator" for 'operator(int)' is saying
that it excpected an operator before the parameter list, e.g. 'operator++' or
'operator()'. Again, technically correct, but could be more user-friendly.