https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91826

--- Comment #1 from MichaƂ <mf at simerics dot com> ---
Previous code compiles fine with clang, but failed with gcc 8.x.
I check similar code that is invalid and should fail with this error: 

namespace N1 {
  namespace N { class C; }
}
namespace N2
{
  namespace A = N1::N;
  class A::C {};
}

This one fail as expected in 9.x & 9.2, but segment fault with 'internal
compiler error' when compiled with gcc 6.3. It is possible that change was made
to correct this problem.

I found that error is printed inside gcc/cp/parser.c when function
'is_ancestor' is used to check if current scope is ancestor of declared class.
This check failed. This function is used at three different location to check
correctness of class/enum scope.

The problem is that namespace alias is not resolved to original namespace
during check and 'is_nested_namespace' function used inside 'is_ancestor' does
not handle namespace aliases. I made change in file gcc/cp/name-lookup.c to
resolve original namespace before calling this function.

Compiler now work for valid code while still print error for invalid above. I
can also build original commercial code that had problem. Change diff is below. 


diff gcc/cp/name-lookup.c ../gcc-9.2.0/gcc/cp/name-lookup.c
4149,4152c4149
<     {
<       child = ORIGINAL_NAMESPACE (child);
<       return is_nested_namespace (root, child);
<     }
---
>     return is_nested_namespace (root, child);

Reply via email to