diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs index 91581064167c..fb009774c4e4 100644 --- a/dist/IO/IO.xs +++ b/dist/IO/IO.xs @@ -397,9 +397,9 @@ ferror(handle) CODE: if (in) #ifdef PerlIO - RETVAL = PerlIO_error(in) || (in != out && PerlIO_error(out)); + RETVAL = PerlIO_error(in) || (out && in != out && PerlIO_error(out)); #else - RETVAL = ferror(in) || (in != out && ferror(out)); + RETVAL = ferror(in) || (out && in != out && ferror(out)); #endif else { RETVAL = -1; diff --git a/dist/IO/t/io_xs.t b/dist/IO/t/io_xs.t index a8833b065123..4657088629fd 100644 --- a/dist/IO/t/io_xs.t +++ b/dist/IO/t/io_xs.t @@ -11,7 +11,7 @@ BEGIN { } } -use Test::More tests => 8; +use Test::More tests => 10; use IO::File; use IO::Seekable; @@ -69,3 +69,11 @@ SKIP: { ok(!$fh->error, "check clearerr removed the error"); close $fh; # silently ignore the error } + +{ + # [GH #18019] IO::Handle->error misreported an error after successully + # opening a regular file for reading. It was a regression in GH #6799 fix. + ok(open(my $fh, '<', __FILE__), "a regular file opened for reading"); + ok(!$fh->error, "no spurious error reported by error()"); + close $fh; +}