From b3e862e09c0adb5dfaae2f538f19dc72948d040b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 1 Dec 2017 15:19:13 -0500 Subject: [PATCH] Give #include hints for . * name-lookup.c (get_std_name_hint): Add . * parser.c (cp_parser_diagnose_invalid_type_name): Call suggest_alternative_in_explicit_scope. (cp_parser_namespace_name): Likewise. From-SVN: r255336 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/name-lookup.c | 3 +++ gcc/cp/parser.c | 11 ++++++++++- gcc/testsuite/g++.dg/lookup/missing-std-include-4.C | 2 ++ gcc/testsuite/g++.dg/lookup/missing-std-include-5.C | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/lookup/missing-std-include-4.C create mode 100644 gcc/testsuite/g++.dg/lookup/missing-std-include-5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 89680a20d6b..5495dc13c69 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2017-12-01 Jason Merrill + Give #include hints for . + * name-lookup.c (get_std_name_hint): Add . + * parser.c (cp_parser_diagnose_invalid_type_name): Call + suggest_alternative_in_explicit_scope. + (cp_parser_namespace_name): Likewise. + PR c++/79228 - extensions hide C++14 complex literal operators * parser.c (cp_parser_userdef_numeric_literal): Be helpful about 'i' in C++14 and up. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 9f65c4d7992..62ea564cedd 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5414,6 +5414,9 @@ get_std_name_hint (const char *name) static const std_name_hint hints[] = { /* . */ {"array", ""}, // C++11 + /* . */ + {"complex", ""}, + {"complex_literals", ""}, /* . */ {"deque", ""}, /* . */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 6e4c24362c6..891f742eb21 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3365,6 +3365,9 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id, id, parser->scope); if (DECL_P (decl)) inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl); + else if (decl == error_mark_node) + suggest_alternative_in_explicit_scope (location, id, + parser->scope); } else if (CLASS_TYPE_P (parser->scope) && constructor_name_p (id, parser->scope)) @@ -18408,7 +18411,13 @@ cp_parser_namespace_name (cp_parser* parser) || TREE_CODE (namespace_decl) != NAMESPACE_DECL) { if (!cp_parser_uncommitted_to_tentative_parse_p (parser)) - error_at (token->location, "%qD is not a namespace-name", identifier); + { + error_at (token->location, "%qD is not a namespace-name", identifier); + if (namespace_decl == error_mark_node + && parser->scope && TREE_CODE (parser->scope) == NAMESPACE_DECL) + suggest_alternative_in_explicit_scope (token->location, identifier, + parser->scope); + } cp_parser_error (parser, "expected namespace-name"); namespace_decl = error_mark_node; } diff --git a/gcc/testsuite/g++.dg/lookup/missing-std-include-4.C b/gcc/testsuite/g++.dg/lookup/missing-std-include-4.C new file mode 100644 index 00000000000..abf4e96bd3e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/missing-std-include-4.C @@ -0,0 +1,2 @@ +std::complex c; // { dg-error "" } +// { dg-message "#include " "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/lookup/missing-std-include-5.C b/gcc/testsuite/g++.dg/lookup/missing-std-include-5.C new file mode 100644 index 00000000000..fe880a6263b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/missing-std-include-5.C @@ -0,0 +1,2 @@ +using namespace std::complex_literals; // { dg-error "" } +// { dg-message "#include " "" { target *-*-* } .-1 } -- 2.30.2