Bug ID: 85269
Summary: warn for referenced standard symbols that aren't
guaranteed to be declared in a header
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
Unlike C, the C++ standard lets standard library implementations structure
headers in whatever way is convenient for them, which extends to having any
header include any other. As a result, writing non-trivial (and sometimes even
trivial) C++ programs that are guaranteed to compile with any conforming C++
compiler can be tricky.
For example, the following compiles successfully with libstdc++ even though it
isn't guaranteed to compile:
void f (std::locale);
on the other hand doesn't compile with libstdc++ because std::locale is only
declared in <string> and not defined. It does, however, compile with Visual
C++ which must be more "promiscuous" than libstdc++ in its header dependencies.
There probably are examples that go the other way around.
It occurs to me that the suggestions G++ issues in response to a program using
a standard symbol without #including the appropriate header could also be used
to provide a warning to help users find the most appropriate header to include
to get each symbol declared. That way, the snippet above would trigger a
warning pointing out that to use std::locale one should #include <locale> first
even if the symbol happens to be declared in the header.