| 1 |
.. Copyright (C) 2024-2025 Free Software Foundation, Inc. |
| 2 |
Originally contributed by David Malcolm <[email protected]> |
| 3 |
|
| 4 |
This is free software: you can redistribute it and/or modify it |
| 5 |
under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation, either version 3 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, but |
| 10 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program. If not, see |
| 16 |
<https://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
.. default-domain:: c |
| 19 |
|
| 20 |
Tutorial part 5: warnings |
| 21 |
========================= |
| 22 |
|
| 23 |
So far we've only emitted errors, but other kinds of diagnostic are possible, |
| 24 |
such as warnings. |
| 25 |
|
| 26 |
We can select different kinds of diagnostic via :enum:`diagnostic_level` |
| 27 |
when calling :func:`diagnostic_begin`: |
| 28 |
|
| 29 |
.. literalinclude:: ../../../testsuite/libgdiagnostics.dg/test-warning.c |
| 30 |
:language: c |
| 31 |
:start-after: /* begin quoted source */ |
| 32 |
:end-before: /* end quoted source */ |
| 33 |
|
| 34 |
On compiling and running the program, we should get output similar to:: |
| 35 |
|
| 36 |
test-warning.c:17:11: warning: this is a warning |
| 37 |
17 | #include <foo.h> |
| 38 |
| ^~~~~ |
| 39 |
|
| 40 |
Various severities are possible, see :enum:`diagnostic_level` for more |
| 41 |
information. |
| 42 |
|
| 43 |
In :doc:`the next section of the tutorial <06-fix-it-hints>` we'll look |
| 44 |
at adding fix-it hints to diagnostics. |