Bug 98306 - invalid use of incomplete type 'struct grammar'
Summary: invalid use of incomplete type 'struct grammar'
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2020-12-15 22:39 UTC by Sergei Trofimovich
Modified: 2021-01-04 15:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2020-12-15 22:39:47 UTC
Noticed error-looking warning when was reducing unrelated boost ICE. Minimal reproducer:

  // $ cat bug.cpp
  extern struct grammar *target_grammar;

  template <typename T> void define(void) { target_grammar->derived(); }

$ g++-11.0.0 -c bug.cpp; echo $?
bug.cpp: In function 'void define()':
bug.cpp:3:57: warning: invalid use of incomplete type 'struct grammar'
    3 | template <typename T> void define(void) { target_grammar->derived(); }
      |                                                         ^~
bug.cpp:1:15: note: forward declaration of 'struct grammar'
    1 | extern struct grammar *target_grammar;
      |               ^~~~~~~
0

$ clang++ -c bug.cpp; echo $?
clang++
bug.cpp:3:57: error: member access into incomplete type 'struct grammar'
template <typename T> void define(void) { target_grammar->derived(); }
                                                        ^
bug.cpp:1:15: note: forward declaration of 'grammar'
extern struct grammar *target_grammar;
              ^
1 error generated.
1

I read the diagnostic with "invalid use" as clearly incorrect code. Should g++ error out instead of generating a warning?
Comment 1 Jakub Jelinek 2020-12-15 22:58:23 UTC
It is only a warning (pedwarn in particular, error with -pedantic-errors) in the uninstantiated template, if you instantiate the template and the type is still incomplete, you get hard error.
Comment 2 Sergei Trofimovich 2020-12-18 22:17:05 UTC
That makes sense. If it's a valid C++ I'm fine with closing the bug as RESOLVED/INVALID.