]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/cpp/diagnostics.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / cpp / diagnostics.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. index:: diagnostic, reporting errors, reporting warnings, #error
7
8.. _diagnostics:
9
10Diagnostics
11-----------
12
13The directive :samp:`#error` causes the preprocessor to report a fatal
14error. The tokens forming the rest of the line following :samp:`#error`
15are used as the error message.
16
17You would use :samp:`#error` inside of a conditional that detects a
18combination of parameters which you know the program does not properly
19support. For example, if you know that the program will not run
20properly on a VAX, you might write
21
22.. code-block:: c++
23
24 #ifdef __vax__
25 #error "Won't work on VAXen. See comments at get_last_object."
26 #endif
27
28If you have several configuration parameters that must be set up by
29the installation in a consistent way, you can use conditionals to detect
30an inconsistency and report it with :samp:`#error`. For example,
31
32.. code-block:: c++
33
34 #if !defined(FOO) && defined(BAR)
35 #error "BAR requires FOO."
36 #endif
37
38.. index:: #warning
39
40The directive :samp:`#warning` is like :samp:`#error`, but causes the
41preprocessor to issue a warning and continue preprocessing. The tokens
42following :samp:`#warning` are used as the warning message.
43
44You might use :samp:`#warning` in obsolete header files, with a message
45directing the user to the header file which should be used instead.
46
47Neither :samp:`#error` nor :samp:`#warning` macro-expands its argument.
48Internal whitespace sequences are each replaced with a single space.
49The line must consist of complete tokens. It is wisest to make the
50argument of these directives be a single string constant; this avoids
3ed1b4ce 51problems with apostrophes and the like.