This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ Patch] PR 26155


Hi,

in this pretty old issue we crash for this testcase:

namespace N
{
  namespace M = N;
  namespace M {}    // { dg-error "namespace alias" }
}

after the error message, because error recovery after error fails. We try to do:

          error ("namespace alias %qD not allowed here, assuming %qD",
             d, DECL_NAMESPACE_ALIAS (d));
          d = DECL_NAMESPACE_ALIAS (d);

but then we crash in resume_scope because:

  /* Also, resuming a non-directly nested namespace is a no-no.  */
  gcc_assert (b->level_chain == current_binding_level);

Thus, in the first patch below I changed push_namespace to stay away from this nasty situation and produce and simpler diagnostics and no special error recovery in this case: a false is returned, and the caller, cp_parser_namespace_definition, makes sure to not call a matching pop_namespace. Diagnostics is good, patch passes testing.

Alternately, the second patch below does the latter unconditionally, without even trying the "assuming" thing. Same diagnostics for the testcase at issue, no regressions in this case too. I don't have a strong personal preference, I suppose the current "assuming" thing may lead to fewer cascading errors, but I don't know for sure, certainly the second patch is simpler.

Thanks,
Paolo.

////////////////////////////////

Attachment: CL_26155
Description: Text document

Attachment: patch_26155
Description: Text document

Attachment: patch_26155_2
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]