https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110164
Bug ID: 110164
Summary: Improve diagnostic for incomplete standard library
types due to missing include
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Target Milestone: ---
If I forget to include a header before using a sufficiently well-known standard
library type, GCC helpfully reminds me of the header:
$ echo 'std::array<int, 10> x;' | g++ -x c++ -
<stdin>:1:6: error: ‘array’ in namespace ‘std’ does not name a template type
<stdin>:1:1: note: ‘std::array’ is defined in header ‘<array>’; did you forget
to ‘#include <array>’?
But if I happen to have a different standard library header included that
happens to bring in a forward declaration of the type, the error message is
less helpful:
$ echo -e '#include <map>\nstd::array<int, 10> x;' | g++ -x c++ -
<stdin>:2:21: error: aggregate ‘std::array<int, 10> x’ has incomplete type and
cannot be defined
It would be nice if the latter case also has a hint about the potential missing
include.