]> gcc.gnu.org Git - gcc.git/commit
c++: provide #include hint for missing includes [PR110164]
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 23 Jun 2023 21:56:14 +0000 (17:56 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 23 Jun 2023 21:56:14 +0000 (17:56 -0400)
commit13709b518aa9769ef427e48ce5c9583fbe098777
treeef85153f19cd97cffba1f43c86dc985123649f4c
parent5388a43f6a3f348929292998bd6d0c1da6f006de
c++: provide #include hint for missing includes [PR110164]

PR c++/110164 notes that in cases where we have a forward decl
of a std library type such as:

std::array<int, 10> x;

we emit this diagnostic:

error: aggregate ‘std::array<int, 10> x’ has incomplete type and cannot be defined

This patch adds this hint to the diagnostic:

note: ‘std::array’ is defined in header ‘<array>’; this is probably fixable by adding ‘#include <array>’

gcc/cp/ChangeLog:
PR c++/110164
* cp-name-hint.h (maybe_suggest_missing_header): New decl.
* decl.cc: Define INCLUDE_MEMORY.  Add include of
"cp/cp-name-hint.h".
(start_decl_1): Call maybe_suggest_missing_header.
* name-lookup.cc (maybe_suggest_missing_header): Remove "static".

gcc/testsuite/ChangeLog:
PR c++/110164
* g++.dg/diagnostic/missing-header-pr110164.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/cp/cp-name-hint.h
gcc/cp/decl.cc
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/diagnostic/missing-header-pr110164.C [new file with mode: 0644]
This page took 0.057863 seconds and 5 git commands to generate.