Commit 490cced4 by Nick Clifton Committed by Nick Clifton

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
parent 7f93abd8
2018-06-15 Nick Clifton <nickc@redhat.com>
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 <rguenther@suse.de>
* tree-vect-slp.c (vect_slp_bb): Dump MSG_OPTIMIZED_LOCATIONS
......
......@@ -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
......
......@@ -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
2018-06-15 Nick Clifton <nickc@redhat.com>
PR 84195
* gcc.c-torture/compile/pr84195.c: New test.
2018-06-15 Richard Biener <rguenther@suse.de>
PR middle-end/86159
......
/* { 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" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment