From: Nick Clifton Date: Fri, 15 Jun 2018 15:25:16 +0000 (+0000) Subject: Force user provided warning and error messages to only occupy one line. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=490cced415071d4c2ea5ef9833c4ab61367471eb;p=gcc.git Force user provided warning and error messages to only occupy one line. PR 84195 gcc: * tree.c (escaped_string): New class. Converts an unescaped string into its escaped equivalent. (warn_deprecated_use): Use the new class to convert the deprecation message, if present. (test_escaped_strings): New self test. (test_c_tests): Add test_escaped_strings. * doc/extend.texi (deprecated): Add a note that the deprecation message is affected by the -fmessage-length option, and that control characters will be escaped. (#pragma GCC error): Document this pragma. (#pragma GCC warning): Likewise. * doc/invoke.texi (-fmessage-length): Document this option's effect on the #warning and #error preprocessor directives and the deprecated attribute. testsuite; * gcc.c-torture/compile/pr84195.c: New test. From-SVN: r261633 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fe7f74cd5a7..d30dc553872 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,21 @@ +2018-06-15 Nick Clifton + + PR 84195 + * tree.c (escaped_string): New class. Converts an unescaped + string into its escaped equivalent. + (warn_deprecated_use): Use the new class to convert the + deprecation message, if present. + (test_escaped_strings): New self test. + (test_c_tests): Add test_escaped_strings. + * doc/extend.texi (deprecated): Add a note that the + deprecation message is affected by the -fmessage-length + option, and that control characters will be escaped. + (#pragma GCC error): Document this pragma. + (#pragma GCC warning): Likewise. + * doc/invoke.texi (-fmessage-length): Document this option's + effect on the #warning and #error preprocessor directives and + the deprecated attribute. + 2018-06-15 Richard Biener * tree-vect-slp.c (vect_slp_bb): Dump MSG_OPTIMIZED_LOCATIONS diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index e0a84b8b3c5..ca96c083f9f 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2553,6 +2553,9 @@ present. The @code{deprecated} attribute can also be used for variables and types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) +The message attached to the attribute is affected by the setting of +the @option{-fmessage-length} option. + @item error ("@var{message}") @itemx warning ("@var{message}") @cindex @code{error} function attribute @@ -6092,6 +6095,9 @@ The @code{deprecated} attribute can also be used for functions and types (@pxref{Common Function Attributes}, @pxref{Common Type Attributes}). +The message attached to the attribute is affected by the setting of +the @option{-fmessage-length} option. + @item nonstring @cindex @code{nonstring} variable attribute The @code{nonstring} variable attribute specifies that an object or member @@ -7018,11 +7024,16 @@ warning is issued for line 4 because T2 is not explicitly deprecated. Line 5 has no warning because T3 is explicitly deprecated. Similarly for line 6. The optional @var{msg} argument, which must be a string, is printed in the warning if -present. +present. Control characters in the string will be replaced with +escape sequences, and if the @option{-fmessage-length} option is set +to 0 (its default value) then any newline characters will be ignored. The @code{deprecated} attribute can also be used for functions and variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.) +The message attached to the attribute is affected by the setting of +the @option{-fmessage-length} option. + @item designated_init @cindex @code{designated_init} type attribute This attribute may only be applied to structure types. It indicates @@ -21973,7 +21984,9 @@ compilation. @cindex pragma, diagnostic Prints @var{string} as a compiler message on compilation. The message -is informational only, and is neither a compilation warning nor an error. +is informational only, and is neither a compilation warning nor an +error. Newlines can be included in the string by using the @samp{\n} +escape sequence. @smallexample #pragma message "Compiling " __FILE__ "..." @@ -21993,6 +22006,37 @@ TODO(Remember to fix this) prints @samp{/tmp/file.c:4: note: #pragma message: TODO - Remember to fix this}. +@item #pragma GCC error @var{message} +@cindex pragma, diagnostic +Generates an error message. This pragma @emph{is} considered to +indicate an error in the compilation, and it will be treated as such. + +Newlines can be included in the string by using the @samp{\n} +escape sequence. They will be displayed as newlines even if the +@option{-fmessage-length} option is set to zero. + +The error is only generated if the pragma is present in the code after +pre-processing has been completed. It does not matter however if the +code containing the pragma is unreachable: + +@smallexample +#if 0 +#pragma GCC error "this error is not seen" +#endif +void foo (void) +@{ + return; +#pragma GCC error "this error is seen" +@} +@end smallexample + +@item #pragma GCC warning @var{message} +@cindex pragma, diagnostic +This is just like @samp{pragma GCC error} except that a warning +message is issued instead of an error message. Unless +@option{-Werror} is in effect, in which case this pragma will generate +an error as well. + @end table @node Visibility Pragmas diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 940b84697fa..3c279ff8efa 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3536,6 +3536,11 @@ Try to format error messages so that they fit on lines of about done; each error message appears on a single line. This is the default for all front ends. +Note - this option also affects the display of the @samp{#error} and +@samp{#warning} pre-processor directives, and the @samp{deprecated} +function/type/variable attribute. It does not however affect the +@samp{pragma GCC warning} and @samp{pragma GCC error} pragmas. + @item -fdiagnostics-show-location=once @opindex fdiagnostics-show-location Only meaningful in line-wrapping mode. Instructs the diagnostic messages diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 262bb2d3585..fc0659608da 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-15 Nick Clifton + + PR 84195 + * gcc.c-torture/compile/pr84195.c: New test. + 2018-06-15 Richard Biener PR middle-end/86159 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr84195.c b/gcc/testsuite/gcc.c-torture/compile/pr84195.c new file mode 100644 index 00000000000..4f1e70bbd76 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr84195.c @@ -0,0 +1,17 @@ +/* { dg-options "-Wdeprecated-declarations" } */ + +/* Check that MSG is printed without the escape characters being interpreted. + Especially the newlines. + + Note - gcc's behaviour is inconsistent in this regard as #error and + #warning will also display control characters as escape sequences, + whereas #pragma GCC error and #pragma GCC warning will perform the + control operations of the control characters. */ + +#define MSG "foo\n\t\rbar" + +int f (int i __attribute__ ((deprecated (MSG)))) +{ + return 0 ? i : 0; /* { dg-warning "'i' is deprecated: foo.n.t.rbar" } */ +} +