aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-04-06 15:46:04 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-04-06 15:46:04 +0000
commitcb731872870ff15c4d4a4dc081191ed607faaa2b (patch)
tree3483741b7ae559112f750a988ecb3cdcd8369315 /gcc/fold-const.c
parenta82f886aa67b81ef2c8499b698c2803f262bb582 (diff)
downloadgcc-cb731872870ff15c4d4a4dc081191ed607faaa2b.zip
gcc-cb731872870ff15c4d4a4dc081191ed607faaa2b.tar.gz
gcc-cb731872870ff15c4d4a4dc081191ed607faaa2b.tar.bz2
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. From-SVN: r259179
Diffstat (limited to 'gcc/fold-const.c')
0 files changed, 0 insertions, 0 deletions