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

            Bug ID: 119747
           Summary: Request for clearer diagnostic when consecutive commas
                    appear in a function call
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Here is a reduced example of a problem I just spent a while debugging:

template <class... Args>
void f(int, Args...) {

}

#define CALL_F(v, ...) f(v, __VA_OPT__(,) __VA_ARGS__)

int main() {
    CALL_F(1, 2);
}

The diagnostic that I get on gcc trunk (so 15, and with c++26 so as to have
__VA_OPT__ support) is:

<source>: In function 'int main()':
<source>:6:40: error: expected primary-expression before ',' token
    6 | #define CALL_F(v, ...) f(v, __VA_OPT__(,) __VA_ARGS__)
      |                                        ^
<source>:9:5: note: in expansion of macro 'CALL_F'
    9 |     CALL_F(1, 2);
      |     ^~~~~~

I couldn't make heads or tails of this diagnostic. And couldn't tell what was
wrong with the code either. 

It wasn't until I preprocessed it that the issue became obvious. I'm doing
this:

int main() {
    f(1, , 2);
}

And gcc is helpfully pointing me to the 2nd comma and saying that I need a
primary-expression before that. Which is true! But it would be a lot more
helpful if the diagnostic told me I had consecutive commas. 

Even something like:

<source>:6:40: error: expected primary-expression before ',' token, received
two consecutive commas

would've meant I would have instantly found the issue.

Reply via email to