https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85021
--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> --- Author: dmalcolm Date: Fri Apr 6 15:46:04 2018 New Revision: 259179 URL: https://gcc.gnu.org/viewcvs?rev=259179&root=gcc&view=rev Log: C++: suggest missing headers for implicit use of "std" (PR c++/85021) We provide fix-it hints for the most common "std" names when an explicit "std::" prefix is present, however we don't yet provide fix-it hints for this implicit case: using namespace std; void f() { cout << "test"; } for which we emit: t.cc: In function 'void f()': t.cc:2:13: error: 'cout' was not declared in this scope void f() { cout << "test"; } ^~~~ This patch detects if a "using namespace std;" directive is present in the current namespace, and if so, offers a suggestion for unrecognized names that are in our list of common "std" names: t.cc: In function 'void f()': t.cc:2:13: error: 'cout' was not declared in this scope void f() { cout << "test"; } ^~~~ t.cc:2:13: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'? +#include <iostream> using namespace std; void f() { cout << "test"; } ^~~~ gcc/cp/ChangeLog: PR c++/85021 * name-lookup.c (using_directives_contain_std_p): New function. (has_using_namespace_std_directive_p): New function. (suggest_alternatives_for): Simplify if/else logic using early returns. If no candidates were found, and there's a "using namespace std;" directive, call maybe_suggest_missing_std_header. (maybe_suggest_missing_header): Split later part of the function into.. (maybe_suggest_missing_std_header): New. gcc/testsuite/ChangeLog: PR c++/85021 * g++.dg/lookup/missing-std-include-7.C: New test. Added: trunk/gcc/testsuite/g++.dg/lookup/missing-std-include-7.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/name-lookup.c trunk/gcc/testsuite/ChangeLog