develooper Front page | perl.perl5.porters | Postings from December 2014

Re: Is the warning fatalization mechanism in fact safe (specificalyFATAL => 'ununitialized')

Thread Previous | Thread Next
December 27, 2014 14:44
Re: Is the warning fatalization mechanism in fact safe (specificalyFATAL => 'ununitialized')
Message ID:
On 27 December 2014 at 12:17, Peter Rabbitson <> wrote:
> An important preamble - this thread is *not* about the lately fashionable
> `use warnings FATAL => 'all';` Instead I want to focus on one very specific
> case to ensure that the discussion doesn't sray ftom the technical details.
> Greetings,
> Over the years I have heard several off-the-record remarks that the FATAL
> warning mechanism is in fact rather broken and can not be relied upon.
> Problems described ranged from "both warning and exception will disappear in
> the ether" to "will corrupt the callstack in cases of DESTROY-unwind FATAL
> warnings".
> Hence I want to check whether the following two snippets from what is
> essentially a common oneliner are in fact 1:1 compatible (from a practical
> point of view) and behave identically, aside from the obvious problem of
> SIG-globalism:
> # 1
> {
>   use warnings FATAL => 'uninitialized';
>   my $nuclear_warhead_code = do { something that should never return undef
> };
>   print STDOUT "Unlock: $nuclear_warhead_arm_code\n";
> }
> # 2
> {
>   my $nuclear_warhead_code = do { something that should never return undef
> };
>   local $SIG{__WARN__} = sub { ($_[0] =~ /uninitialized value/)
>     ? die $_[0]
>     : warn $_[0]
>   };
>   print STDOUT "Unlock: $nuclear_warhead_arm_code\n";
> }
> The examples are deliberately stupid - I want to facilitate a discussion of
> what happens in the perl guts, as opposed to "this is not something you
> should be doing anyway".

IMO these examples are *too* stupid. The second does not enabled
warnings at all, so no, it is not the same as the first.

Both have the issue that you define $nuclear_warhead_code but you do
not define $nuclear_warhead_arm_code.

Anyway, with various corrections I would say these two snippets are
relatively equivalent. There are some subtleties involved IMO, for

warn "I encountered an uninitialized value";

would trigger the second but not the first AFAIK.

You speak of issues related to warning fatal, It would be nice to see
a reproduction script before we give this rumour credence, otherwise
it is just FUD.


perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About