On 10/11/19 6:31 PM, Jason Merrill wrote: > On 10/10/19 2:06 PM, Bernd Edlinger wrote: >> On 10/10/19 7:49 PM, Jason Merrill wrote: >>> On 10/10/19 10:42 AM, Bernd Edlinger wrote: >>>> Hi, >>>> >>>> this fixes a crash when -Wshadow=compatible-local is >>>> enabled in the testcase g++.dg/parse/crash68.C >>> >>> Why does that flag cause this crash? >>> >> >> gcc/cp/name-lookup.c: >> >>        if (warn_shadow) >>          warning_code = OPT_Wshadow; >>        else if (warn_shadow_local) >>          warning_code = OPT_Wshadow_local; >>        else if (warn_shadow_compatible_local >>                 && (same_type_p (TREE_TYPE (old), TREE_TYPE (decl)) >>                     || (!dependent_type_p (TREE_TYPE (decl)) >>                         && !dependent_type_p (TREE_TYPE (old)) >>                         /* If the new decl uses auto, we don't yet know >>                            its type (the old type cannot be using auto >>                            at this point, without also being >>                            dependent).  This is an indication we're >>                            (now) doing the shadow checking too >>                            early.  */ >>                         && !type_uses_auto (TREE_TYPE (decl)) >>                         && can_convert (TREE_TYPE (old), TREE_TYPE (decl), >>                                         tf_none)))) >>          warning_code = OPT_Wshadow_compatible_local; >> >> if -Wshadow=compatible-local is used, the can_convert function crashes >> in instantiate_class_template_1. > > Right, checking can_convert is problematic here, as it can cause template instantiations that change the semantics of the program.  Or, in this case, crash. > So I try to make C++ behave more consistently with the code in c-decl.c, thus dependent on warn_shadow but not on warn_shadow_local and/or warn_shadow_compatible_local: if (warn_shadow) warning_code = OPT_Wshadow; else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl))) warning_code = OPT_Wshadow_compatible_local; else warning_code = OPT_Wshadow_local; warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code, "declaration of %qD shadows a parameter", new_decl); I cannot remove the if (warn_shadow) since this breaks gcc.dg/pr48062.c which uses: #pragma GCC diagnostic ignored "-Wshadow" to disable a -Wshadow=compatible-local warning, but while -Wno-shadow on the command line disables also dependent warnings the pragma does not (always) do that. So instead I'd like to adjust the doc of -Wshadow to reflect the implementation and remove the if(warn_shadow_local) to have C and C++ behave identical and hopefully now in sync with the doc. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd.