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

            Bug ID: 102774
           Summary: Stop showing "error: variable or field ‘f’ declared
                    void" after an earlier error in a declarator
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
            Blocks: 16663
  Target Milestone: ---

Consider the example in PR 102771 and its errors:

vart.C:1:18: error: expected nested-name-specifier before ‘.’ token
    1 | template<typename.. T> void f(T...) { }
      |                  ^
vart.C:1:18: error: expected ‘>’ before ‘.’ token
vart.C:1:29: error: variable or field ‘f’ declared void
    1 | template<typename.. T> void f(T...) { }
      |                             ^
vart.C:1:31: error: ‘T’ was not declared in this scope
    1 | template<typename.. T> void f(T...) { }
      |                               ^


G++ often prints some variation of "variable or field ‘f’ declared void" and
it's rarely helpful in practice.

I think that error is intended for cases like:

void f;

But this is probably rare, and in practice the diagnostic gets printed **all
the time** for code that isn't doing this at all. In the example above we have
an almost valid function declaration, except for the typo in the template-head.
Once we've hit that typo (and shown an error for it), it's reasonable for the
rest of the declarator to fail to parse, but the "declared void" is just
nonsense. The only problem is the bad '...' token, but if we can't recover from
that then

If we've already hit at least one error in a given declarator, maybe we should
suppress the "declared void" diagnostic. It's almost certainly due to poor
error recovery after the first error.

Or at least change the wording, so that it says something like "could not parse
invalid declrator".

"variable of field 'f' declared void" for a function declaration is just bad.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16663
[Bug 16663] Poor parse error recovery with mispelled type in function
declaration

Reply via email to