aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-09-05 17:26:59 +0200
committerJakub Jelinek <jakub@redhat.com>2023-09-05 17:26:59 +0200
commitc24982689b8af19da9a64f2283fb99764a1c5db0 (patch)
tree017b63e4d4661390c270698def251576e8aeecde /gcc/c
parente87212ead5e9f36945b5e2d290187e2adca34da5 (diff)
downloadgcc-c24982689b8af19da9a64f2283fb99764a1c5db0.zip
gcc-c24982689b8af19da9a64f2283fb99764a1c5db0.tar.gz
gcc-c24982689b8af19da9a64f2283fb99764a1c5db0.tar.bz2
c++: Diagnose [basic.scope.block]/2 violations even in compound-stmt of function-try-block [PR52953]
As the following testcase shows, while check_local_shadow diagnoses most of the [basic.scope.block]/2 violations, it doesn't diagnose when parameter's name is redeclared inside of the compound-stmt of a function-try-block. There is in that case an extra scope (sk_try with parent artificial sk_block with for FUNCTION_NEEDS_BODY_BLOCK another sk_block and only then sk_function_param). The in_function_try_handler case doesn't work correctly void foo (int x) try { } catch (int) { try { } catch (int x) { } try { } catch (int) { int x; } } (which is valid) is rejected, because || (TREE_CODE (old) == PARM_DECL && (current_binding_level->kind == sk_catch || current_binding_level->level_chain->kind == sk_catch) && in_function_try_handler)) is true but nothing verified that for the first case current_binding_level->level_chain->kind == sk_function_params (with perhaps artificial scopes in between and in the latter case with one extra level in between). The patch also changes behavior where for catch handlers of function-try-block the diagnostics will have the shadows function parameter wording as pedwarn rather than the old redeclaration permerror. 2023-09-05 Jakub Jelinek <jakub@redhat.com> PR c++/52953 * name-lookup.h (struct cp_binding_level): Add artificial bit-field. Formatting fixes. * name-lookup.cc (check_local_shadow): Skip artificial bindings when checking if parameter scope is parent scope. Don't special case FUNCTION_NEEDS_BODY_BLOCK. Diagnose the in_function_try_handler cases in the b->kind == sk_function_parms test and verify no non-artificial intervening scopes. Add missing auto_diagnostic_group. * decl.cc (begin_function_body): Set current_binding_level->artificial. * semantics.cc (begin_function_try_block): Likewise. * g++.dg/diagnostic/redeclaration-1.C: Expect different diagnostic wording. * g++.dg/diagnostic/redeclaration-3.C: New test. * g++.dg/parse/pr31952-1.C: Expect different diagnostic wording. * g++.dg/parse/pr31952-3.C: Likewise.
Diffstat (limited to 'gcc/c')
0 files changed, 0 insertions, 0 deletions