From 2fe89a7e263fb1d8a7cb283a4021ded0b35b528f Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 4 Sep 2024 11:16:03 +1000 Subject: [PATCH] ck_open: report bareword dup handles under no feature bareword_filehandles --- op.c | 7 +++++-- t/lib/feature/bareword_filehandles | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index d6f960e077..3126002e00 100644 --- a/op.c +++ b/op.c @@ -13487,8 +13487,11 @@ Perl_ck_open(pTHX_ OP *o) (oa = OpSIBLING(first)) && /* The fh. */ (oa = OpSIBLING(oa)) && /* The mode. */ S_is_dup_mode(oa) && /* A dup open. */ - (last == OpSIBLING(oa))) /* The bareword. */ - last->op_private &= ~OPpCONST_STRICT; + (last == OpSIBLING(oa))) { /* The bareword. */ + if (!FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED) + no_bareword_filehandle(SvPVX(cSVOPx_sv(last))); + last->op_private &= ~OPpCONST_STRICT; + } } { /* mark as special if filename is a literal undef */ diff --git a/t/lib/feature/bareword_filehandles b/t/lib/feature/bareword_filehandles index d8c5742d34..e7f5c24b3e 100644 --- a/t/lib/feature/bareword_filehandles +++ b/t/lib/feature/bareword_filehandles @@ -556,3 +556,15 @@ Beta stdout >Delta >Epsilon +######## +# NAME bareword handle in open dup handle calls +use strict; +open BAREWORD, ">&", STDOUT; +open my $fh2, ">&", BAREWORD; +no feature "bareword_filehandles"; +open my $fh3, ">&", STDOUT; +open my $fh4, ">&", BAREWORD; +EXPECT +OPTIONS fatal +Bareword filehandle "BAREWORD" not allowed under 'no feature "bareword_filehandles"' at - line 6. +Execution of - aborted due to compilation errors.