syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

There's a new warning in perl-5.38.0 in relation to locales that have the potential to crash perl. On Windows:
> perl -MPOSIX="setlocale" -le "$loc = setlocale( LC_ALL, 'Korean_Kore +a.949' ); print 'LOCALE: ' . $loc;" Locale 'Korean_Korea.949' is unsupported, and may crash the interprete +r. LOCALE: Korean_Korea.949
Note that there's no accompanying info indicating which line of code triggered the error.
Is that a bug ? Is there some documentation that definitively answers that question ?
Are there any precedents of other warnings that also don't provide that information ?

The line number info is suppressed because the diagnostic message terminates with "\n".
The warning originates from locale.c, and removing the "\n" enables the line number info to be provided. Inline::C demo:
### try.pl ### use strict; use warnings; use Inline C => <<'EOC'; void foo() { Perl_ck_warner_d(aTHX_ packWARN(WARN_LOCALE), "Locale is unsupported, and may crash the" " interpreter.\n" ); } void bar() { Perl_ck_warner_d(aTHX_ packWARN(WARN_LOCALE), "Locale is unsupported, and may crash the" " interpreter" ); } EOC foo(); bar(); __END__ Outputs: Locale is unsupported, and may crash the interpreter. Locale is unsupported, and may crash the interpreter at try.pl line 24 +.
I suppose I could just file an issue, and see what the response is.
But anyway, I'm interested to know how others here assess this issue.

Cheers,
Rob

Replies are listed 'Best First'.
Re: Warning given, but no line number provided.
by LanX (Saint) on Aug 08, 2023 at 13:54 UTC
    warn messages terminating on newline don't show the location.

    It's documented and I use that trick regularly to adjust the location.

    Update

    Hmm ... It seems only to be documented for die

    > If the string exception does not end in a newline, the current script line number and input line number (if any) and a newline are appended to it

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

      It's documented and I use that trick regularly to adjust the location.

      Yes, I use the same trick, too - mainly in test suite scripts when I want to print an informative message (that's not actually a warning) to STDERR.
      In such situations one doesn't want an "at line ..." appendix to appear, and doing warn "message\n" is less typing than print STDERR "message\n".

      But, in this case with the problematic locale, I'm thinking the message is actually intended as a warning - and is enabled by the warnings pragma loaded by POSIX.pm.
      Without the presence of the warnings pragma, that new locale warning won't appear ... and I'm wondering why the line number info is suppressed for this warning, yet every other warning from core perl that's enabled by the warnings pragma provides the additional info (AFAIK). Is it oversight or intentional ?

      Maybe none of this matters - it just struck me as odd that perl would emit this warning (when warnings are enabled), but then withhold the location info.

      UPDATE: As per hv's suggestion below, https://github.com/Perl/perl5/issues/21352 has been created.

      Cheers,
      Rob

        I think it is very likely an oversight - I believe this is part of the ongoing series of improvements to locale handling by Karl Williamson. Please do report it.