This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix handling of registered warning categories
[perl5.git] / warnings.h
index 24fe243..c2831a2 100644 (file)
 
 #define WARN_EXPERIMENTAL               51
 #define WARN_EXPERIMENTAL__LEXICAL_SUBS         52
-#define WARN_EXPERIMENTAL__LEXICAL_TOPIC 53
-#define WARN_EXPERIMENTAL__REGEX_SETS   54
-#define WARN_EXPERIMENTAL__SMARTMATCH   55
+#define WARN_EXPERIMENTAL__REGEX_SETS   53
+#define WARN_EXPERIMENTAL__SMARTMATCH   54
 
 /* Warnings Categories added in Perl 5.019 */
 
-#define WARN_EXPERIMENTAL__AUTODEREF    56
-#define WARN_EXPERIMENTAL__POSTDEREF    57
-#define WARN_EXPERIMENTAL__SIGNATURES   58
-#define WARN_SYSCALLS                   59
+#define WARN_EXPERIMENTAL__POSTDEREF    55
+#define WARN_EXPERIMENTAL__SIGNATURES   56
+#define WARN_SYSCALLS                   57
 
 /* Warnings Categories added in Perl 5.021 */
 
-#define WARN_EXPERIMENTAL__BITWISE      60
-#define WARN_EXPERIMENTAL__CONST_ATTR   61
-#define WARN_EXPERIMENTAL__RE_STRICT    62
-#define WARN_EXPERIMENTAL__REFALIASING  63
-#define WARN_EXPERIMENTAL__WIN32_PERLIO         64
-#define WARN_LOCALE                     65
-#define WARN_MISSING                    66
-#define WARN_REDUNDANT                  67
+#define WARN_EXPERIMENTAL__BITWISE      58
+#define WARN_EXPERIMENTAL__CONST_ATTR   59
+#define WARN_EXPERIMENTAL__RE_STRICT    60
+#define WARN_EXPERIMENTAL__REFALIASING  61
+#define WARN_EXPERIMENTAL__WIN32_PERLIO         62
+#define WARN_LOCALE                     63
+#define WARN_MISSING                    64
+#define WARN_REDUNDANT                  65
+
+/* Warnings Categories added in Perl 5.025 */
+
+#define WARN_EXPERIMENTAL__DECLARED_REFS 66
 
 #define WARNsize                        17
 #define WARN_ALLstring                  "\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125"
 #define WARN_NONEstring                         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
 
-#define isLEXWARN_on   (PL_curcop->cop_warnings != pWARN_STD)
-#define isLEXWARN_off  (PL_curcop->cop_warnings == pWARN_STD)
+#define isLEXWARN_on \
+       cBOOL(PL_curcop && PL_curcop->cop_warnings != pWARN_STD)
+#define isLEXWARN_off \
+       cBOOL(!PL_curcop || PL_curcop->cop_warnings == pWARN_STD)
 #define isWARN_ONCE    (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
 #define isWARN_on(c,x) (IsSet((U8 *)(c + 1), 2*(x)))
 #define isWARNf_on(c,x)        (IsSet((U8 *)(c + 1), 2*(x)+1))
     : (STRLEN*)CopyD(p, PerlMemShared_malloc(sizeof(*p)+*p), sizeof(*p)+*p, \
                                             char))
 
+/*
+
+=head1 Warning and Dieing
+
+=for apidoc Am|bool|ckWARN|U32 w
+
+Returns a boolean as to whether or not warnings are enabled for the warning
+category C<w>.  If the category is by default enabled even if not within the
+scope of S<C<use warnings>>, instead use the L</ckWARN_d> macro.
+
+=for apidoc Am|bool|ckWARN_d|U32 w
+
+Like C<L</ckWARN>>, but for use if and only if the warning category is by
+default enabled even if not within the scope of S<C<use warnings>>.
+
+=for apidoc Am|bool|ckWARN2|U32 w1|U32 w2
+
+Like C<L</ckWARN>>, but takes two warnings categories as input, and returns
+TRUE if either is enabled.  If either category is by default enabled even if
+not within the scope of S<C<use warnings>>, instead use the L</ckWARN2_d>
+macro.  The categories must be completely independent, one may not be
+subclassed from the other.
+
+=for apidoc Am|bool|ckWARN2_d|U32 w1|U32 w2
+
+Like C<L</ckWARN2>>, but for use if and only if either warning category is by
+default enabled even if not within the scope of S<C<use warnings>>.
+
+=for apidoc Am|bool|ckWARN3|U32 w1|U32 w2|U32 w3
+
+Like C<L</ckWARN2>>, but takes three warnings categories as input, and returns
+TRUE if any is enabled.  If any of the categories is by default enabled even
+if not within the scope of S<C<use warnings>>, instead use the L</ckWARN3_d>
+macro.  The categories must be completely independent, one may not be
+subclassed from any other.
+
+=for apidoc Am|bool|ckWARN3_d|U32 w1|U32 w2|U32 w3
+
+Like C<L</ckWARN3>>, but for use if and only if any of the warning categories
+is by default enabled even if not within the scope of S<C<use warnings>>.
+
+=for apidoc Am|bool|ckWARN4|U32 w1|U32 w2|U32 w3|U32 w4
+
+Like C<L</ckWARN3>>, but takes four warnings categories as input, and returns
+TRUE if any is enabled.  If any of the categories is by default enabled even
+if not within the scope of S<C<use warnings>>, instead use the L</ckWARN4_d>
+macro.  The categories must be completely independent, one may not be
+subclassed from any other.
+
+=for apidoc Am|bool|ckWARN4_d|U32 w1|U32 w2|U32 w3|U32 w4
+
+Like C<L</ckWARN4>>, but for use if and only if any of the warning categories
+is by default enabled even if not within the scope of S<C<use warnings>>.
+
+=cut
+
+*/
+
 #define ckWARN(w)              Perl_ckwarn(aTHX_ packWARN(w))
 
 /* The w1, w2 ... should be independent warnings categories; one shouldn't be
 #define unpackWARN4(x)         (((x) >>24) & 0xFF)
 
 #define ckDEAD(x)                                                      \
-          ( ! specialWARN(PL_curcop->cop_warnings) &&                  \
-           ( isWARNf_on(PL_curcop->cop_warnings, WARN_ALL) ||          \
-             isWARNf_on(PL_curcop->cop_warnings, unpackWARN1(x)) ||    \
-             isWARNf_on(PL_curcop->cop_warnings, unpackWARN2(x)) ||    \
-             isWARNf_on(PL_curcop->cop_warnings, unpackWARN3(x)) ||    \
-             isWARNf_on(PL_curcop->cop_warnings, unpackWARN4(x))))
+   (PL_curcop &&                                                        \
+    !specialWARN(PL_curcop->cop_warnings) &&                           \
+    (isWARNf_on(PL_curcop->cop_warnings, unpackWARN1(x)) ||            \
+      (unpackWARN2(x) &&                                                \
+       (isWARNf_on(PL_curcop->cop_warnings, unpackWARN2(x)) ||         \
+         (unpackWARN3(x) &&                                            \
+           (isWARNf_on(PL_curcop->cop_warnings, unpackWARN3(x)) ||     \
+             (unpackWARN4(x) &&                                        \
+               isWARNf_on(PL_curcop->cop_warnings, unpackWARN4(x)))))))))
 
 /* end of file warnings.h */