summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_sort.c8
-rw-r--r--t/lib/warnings/9uninit16
2 files changed, 24 insertions, 0 deletions
diff --git a/pp_sort.c b/pp_sort.c
index fafa00acf2..0ee42dcf38 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1874,6 +1874,14 @@ S_sv_ncmp(pTHX_ SV *const a, SV *const b)
PERL_ARGS_ASSERT_SV_NCMP;
+#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
+ if (Perl_isnan(right) || Perl_isnan(left)) {
+#else
+ if (nv1 != nv1 || nv2 != nv2) {
+#endif
+ if (ckWARN(WARN_UNINITIALIZED)) report_uninit(NULL);
+ return 0;
+ }
return nv1 < nv2 ? -1 : nv1 > nv2 ? 1 : 0;
}
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit
index a30352a279..b79fc015bb 100644
--- a/t/lib/warnings/9uninit
+++ b/t/lib/warnings/9uninit
@@ -655,6 +655,22 @@ Use of uninitialized value $g1 in sort at - line 9.
Use of uninitialized value in sort at - line 10.
Use of uninitialized value in sort at - line 11.
########
+my $nan = sin 9**9**9;
+if ($nan == $nan) {
+ print <<EOM ;
+SKIPPED
+# No nan support
+EOM
+ exit ;
+}
+use warnings 'uninitialized';
+# The optimised {$a<=>$b} case should behave the same way as unoptimised.
+@sort = sort { ($a)[0] <=> $b } 1, $nan;
+@sort = sort { $a <=> $b } 1, $nan;
+EXPECT
+Use of uninitialized value in sort at - line 11.
+Use of uninitialized value in sort at - line 12.
+########
use warnings 'uninitialized';
my ($m1, $m2, $v);
our ($g1);