Re: C++ PATCH to fix ICE with suggestions (PR c++/84537)

2018-02-26 Thread Jason Merrill
OK.

On Mon, Feb 26, 2018 at 4:44 AM, Marek Polacek  wrote:
> Here error_mark_node leaks all the way to edit_distance_traits::get_string
> which crashed, so let's not try to give a suggestion for an error node in
> the first place.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-02-26  Marek Polacek  
>
> PR c++/84537
> * name-lookup.c (suggest_alternative_in_explicit_scope): Return false
> if name is error node.
>
> * g++.dg/parse/error60.C: New test.
>
> diff --git gcc/cp/name-lookup.c gcc/cp/name-lookup.c
> index 9117e0b30eb..0f00328e96e 100644
> --- gcc/cp/name-lookup.c
> +++ gcc/cp/name-lookup.c
> @@ -5541,6 +5541,10 @@ bool
>  suggest_alternative_in_explicit_scope (location_t location, tree name,
>tree scope)
>  {
> +  /* Something went very wrong; don't suggest anything.  */
> +  if (name == error_mark_node)
> +return false;
> +
>/* Resolve any namespace aliases.  */
>scope = ORIGINAL_NAMESPACE (scope);
>
> diff --git gcc/testsuite/g++.dg/parse/error60.C 
> gcc/testsuite/g++.dg/parse/error60.C
> index e69de29bb2d..38f4e34c59d 100644
> --- gcc/testsuite/g++.dg/parse/error60.C
> +++ gcc/testsuite/g++.dg/parse/error60.C
> @@ -0,0 +1,9 @@
> +// PR c++/84537
> +// { dg-do compile }
> +
> +namespace N
> +{
> +  template struct A {};
> +}
> +
> +N::template A<> a; // { dg-error "" }
>
> Marek


C++ PATCH to fix ICE with suggestions (PR c++/84537)

2018-02-26 Thread Marek Polacek
Here error_mark_node leaks all the way to edit_distance_traits::get_string
which crashed, so let's not try to give a suggestion for an error node in
the first place.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-02-26  Marek Polacek  

PR c++/84537
* name-lookup.c (suggest_alternative_in_explicit_scope): Return false
if name is error node.

* g++.dg/parse/error60.C: New test.

diff --git gcc/cp/name-lookup.c gcc/cp/name-lookup.c
index 9117e0b30eb..0f00328e96e 100644
--- gcc/cp/name-lookup.c
+++ gcc/cp/name-lookup.c
@@ -5541,6 +5541,10 @@ bool
 suggest_alternative_in_explicit_scope (location_t location, tree name,
   tree scope)
 {
+  /* Something went very wrong; don't suggest anything.  */
+  if (name == error_mark_node)
+return false;
+
   /* Resolve any namespace aliases.  */
   scope = ORIGINAL_NAMESPACE (scope);
 
diff --git gcc/testsuite/g++.dg/parse/error60.C 
gcc/testsuite/g++.dg/parse/error60.C
index e69de29bb2d..38f4e34c59d 100644
--- gcc/testsuite/g++.dg/parse/error60.C
+++ gcc/testsuite/g++.dg/parse/error60.C
@@ -0,0 +1,9 @@
+// PR c++/84537
+// { dg-do compile }
+
+namespace N
+{
+  template struct A {};
+}
+
+N::template A<> a; // { dg-error "" }

Marek