Description
m/(?:\g{-1}|(ab?))+/ terminates.
Steps to Reproduce
\g{1} vs \g{-1}:
perl -wle ' print "\$&:[$&],\$1:[$1]" if "aab" =~ m/(?:\g{1}|(ab?))+/ '
perl-5.38.2
==========
$&:[aa],$1:[a]
perl -wle ' print "\$&:[$&],\$1:[$1]" if "aab" =~ m/(?:\g{-1}|(ab?))+/ '
perl-5.38.2
==========
Reference to nonexistent or unclosed group in regex; marked by <-- HERE in m/(?:\g{- <-- HERE 1}|(ab?))+/ at -e line 1.
Command terminated with non-zero status.
Here is an example with working regex containing \g{-1} inside of its group (modified from #10073 ):
perlbrew exec perl -wle 'print "not ok" if "xa=xaaa" =~ /^(xa|=?\g{-1}a){2}$/'
perl-5.38.2
==========
perl-5.36.0
==========
not ok
(...same output as with \g{1})
Expected behavior
m/(?:\g{-1}|(ab?))+/ - should it work the same as with \g{1}?