+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
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
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
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
@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__ "..."
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
--- /dev/null
+/* { 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" } */
+}
+