From: Sam Tregar Date: Sun, 6 Jan 2002 00:29:25 +0000 (-0500) Subject: Bad prototype detection now an optional warning X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=420cdfc116ef70c5fc76ac6f0fd68df66919fd46;p=p5sagit%2Fp5-mst-13.2.git Bad prototype detection now an optional warning Message-Id: p4raw-id: //depot/perl@14101 --- diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 0ae001b..2ef1f41 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -224,6 +224,13 @@ The tr///C and tr///U features have been removed and will not return; the interface was a mistake. Sorry about that. For similar functionality, see pack('U0', ...) and pack('C0', ...). +=item * + +Earlier Perls treated "sub foo (@bar)" as equivalent to "sub foo (@)". +The prototypes are now checked at compile-time for invalid characters. +An optional warning is generated ("Illegal character in prototype...") +but this may be upgraded to a fatal error in a future release. + =back =head1 Core Enhancements diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 29358ea..777b0dd 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1612,7 +1612,7 @@ to your Perl administrator. =item Illegal character in prototype for %s : %s -(S) An illegal character was found in a prototype declaration. Legal +(W syntax) An illegal character was found in a prototype declaration. Legal characters in prototypes are $, @, %, *, ;, [, ], &, and \. =item Illegal division by zero diff --git a/pod/perlsub.pod b/pod/perlsub.pod index aa5fd5b..a1bba6e 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -1021,6 +1021,13 @@ programmers, and that it will not intrude greatly upon the meat of the module, nor make it harder to read. The line noise is visually encapsulated into a small pill that's easy to swallow. +If you try to use an alphanumeric sequence in a prototype you will +generate an optional warning - "Illegal character in prototype...". +Unfortunately earlier versions of Perl allowed the prototype to be +used as long as its prefix was a valid prototype. The warning may be +upgraded to a fatal error in a future version of Perl once the +majority of offending code is fixed. + It's probably best to prototype new functions, not retrofit prototyping into older ones. That's because you must be especially careful about silent impositions of differing list versus scalar contexts. For example, diff --git a/t/comp/proto.t b/t/comp/proto.t index 4141f2a..e020be7 100755 --- a/t/comp/proto.t +++ b/t/comp/proto.t @@ -547,6 +547,7 @@ print "ok ", $i++, "\n"; # check that obviously bad prototypes are getting warnings { + use warnings 'syntax'; my $warn = ""; local $SIG{__WARN__} = sub { $warn .= join("",@_) }; diff --git a/toke.c b/toke.c index 6f06daa..3046bb5 100644 --- a/toke.c +++ b/toke.c @@ -4968,10 +4968,10 @@ Perl_yylex(pTHX) } } d[tmp] = '\0'; - if (bad_proto) - Perl_warn(aTHX_ - "Illegal character in prototype for %s : %s", - SvPVX(PL_subname), d); + if (bad_proto && ckWARN(WARN_SYNTAX)) + Perl_warner(aTHX_ WARN_SYNTAX, + "Illegal character in prototype for %s : %s", + SvPVX(PL_subname), d); SvCUR(PL_lex_stuff) = tmp; have_proto = TRUE;