From fcb2cdfcfecc800d537fffa13dad17e4a3a34ae2 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 31 Jan 2017 21:30:42 +0000 Subject: [PATCH] Fix ICE with spelling hints within explicit namespace aliases (PR c++/79298) gcc/cp/ChangeLog: PR c++/79298 * name-lookup.c (suggest_alternative_in_explicit_scope): Resolve any namespace aliases. gcc/testsuite/ChangeLog: PR c++/79298 * g++.dg/spellcheck-pr79298.C: New test case. From-SVN: r245072 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/name-lookup.c | 3 +++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/spellcheck-pr79298.C | 17 +++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/spellcheck-pr79298.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2a8660796e1..04d2a6017e8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-01-31 David Malcolm + + PR c++/79298 + * name-lookup.c (suggest_alternative_in_explicit_scope): Resolve + any namespace aliases. + 2017-01-31 Nathan Sidwell PR c++/79290 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index a3cb7eea907..994f7f0c5c3 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4545,6 +4545,9 @@ bool suggest_alternative_in_explicit_scope (location_t location, tree name, tree scope) { + /* Resolve any namespace aliases. */ + scope = ORIGINAL_NAMESPACE (scope); + cp_binding_level *level = NAMESPACE_LEVEL (scope); best_match bm (name); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f7cf0f489a2..ef50edab562 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-01-31 David Malcolm + + PR c++/79298 + * g++.dg/spellcheck-pr79298.C: New test case. + 2017-01-31 David Malcolm PR preprocessor/79210 diff --git a/gcc/testsuite/g++.dg/spellcheck-pr79298.C b/gcc/testsuite/g++.dg/spellcheck-pr79298.C new file mode 100644 index 00000000000..4d7bbf9ca92 --- /dev/null +++ b/gcc/testsuite/g++.dg/spellcheck-pr79298.C @@ -0,0 +1,17 @@ +// Ensure that we can offer suggestions for misspellings via a +// namespace alias. + +namespace N { int x; int color; } +namespace M = N; +namespace O = M; + +int foo () +{ + return M::y; // { dg-error ".y. is not a member of .M." } +} + +int bar () +{ + return O::colour; // { dg-error ".colour. is not a member of .O." } + // { dg-message "suggested alternative: .color." "" { target *-*-* } .-1 } +} -- 2.30.2