GCC Middle and Back End API Reference
diagnostic-core.h
Go to the documentation of this file.
1/* Declarations of core diagnostic functionality for code that does
2 not need to deal with diagnostic contexts or diagnostic info
3 structures. These functions implicitly use global_dc.
4 Copyright (C) 1998-2025 Free Software Foundation, Inc.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_DIAGNOSTIC_CORE_H
23#define GCC_DIAGNOSTIC_CORE_H
24
25#include "bversion.h"
26#include "diagnostics/kinds.h"
28
29/* RAII-style class for grouping related diagnostics within global_dc. */
30
37
38/* RAII-style class for nesting hierarchical diagnostics within global_dc.
39 Any diagnostics emitted within the lifetime of this object
40 will be treated as one level of nesting deeper than diagnostics
41 emitted outside the lifetime of the object. */
42
49
50/* Forward decl. */
51namespace diagnostics {
52 class metadata; /* See diagnostics/metadata.h. */
53} // namespace diagnostics
54
55extern const char *progname;
56
57extern const char *trim_filename (const char *);
58
59/* Various functions for emitting diagnostics follow.
60 All of these implicitly use global_dc. */
61
62/* If we haven't already defined a front-end-specific diagnostics
63 style, use the generic one. */
64#ifndef GCC_DIAG_STYLE
65#define GCC_DIAG_STYLE __gcc_tdiag__
66#endif
67/* None of these functions are suitable for ATTRIBUTE_PRINTF, because
68 each language front end can extend them with its own set of format
69 specifiers. We must use custom format checks. */
70#if (CHECKING_P && GCC_VERSION >= 4001) || GCC_VERSION == BUILDING_GCC_VERSION
71#define ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
72#else
73#define ATTRIBUTE_GCC_DIAG(m, n) ATTRIBUTE_NONNULL(m)
74#endif
75extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
77extern void internal_error_no_backtrace (const char *, ...)
79/* Pass one of the OPT_W* from options.h as the first parameter. */
80extern bool warning (diagnostics::option_id,
81 const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
82extern bool warning_n (location_t,
83 diagnostics::option_id,
84 unsigned HOST_WIDE_INT,
85 const char *, const char *, ...)
87extern bool warning_n (rich_location *,
88 diagnostics::option_id,
89 unsigned HOST_WIDE_INT,
90 const char *, const char *, ...)
92extern bool warning_at (location_t,
93 diagnostics::option_id,
94 const char *, ...)
96extern bool warning_at (rich_location *,
97 diagnostics::option_id,
98 const char *, ...)
100extern bool warning_meta (rich_location *,
101 const diagnostics::metadata &,
102 diagnostics::option_id,
103 const char *, ...)
105extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
106extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *,
107 const char *, ...)
109extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
110extern void error_at (rich_location *, const char *, ...)
112extern void error_meta (rich_location *, const diagnostics::metadata &,
113 const char *, ...)
115extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
117/* Pass one of the OPT_W* from options.h as the second parameter. */
118extern bool pedwarn (location_t,
119 diagnostics::option_id,
120 const char *, ...)
122extern bool pedwarn (rich_location *,
123 diagnostics::option_id,
124 const char *, ...)
126extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
127extern bool permerror (rich_location *, const char *,
128 ...) ATTRIBUTE_GCC_DIAG(2,3);
129extern bool permerror_opt (location_t,
130 diagnostics::option_id,
131 const char *, ...)
133extern bool permerror_opt (rich_location *,
134 diagnostics::option_id,
135 const char *, ...)
137extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
138extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
139extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
140extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
141extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
142 const char *, ...)
144extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
145extern bool emit_diagnostic (enum diagnostics::kind,
146 location_t,
147 diagnostics::option_id,
148 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
149extern bool emit_diagnostic (enum diagnostics::kind,
150 rich_location *,
151 diagnostics::option_id,
152 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
153extern bool emit_diagnostic_valist (enum diagnostics::kind,
154 location_t,
155 diagnostics::option_id,
156 const char *, va_list *)
157 ATTRIBUTE_GCC_DIAG (4,0);
159 rich_location *,
160 const diagnostics::metadata *,
161 diagnostics::option_id,
162 const char *,
163 va_list *) ATTRIBUTE_GCC_DIAG (5,0);
164extern bool seen_error (void);
165
166#ifdef BUFSIZ
167 /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and
168 therefore it can have ATTRIBUTE_PRINTF. */
169extern void fnotice (FILE *, const char *, ...)
170 ATTRIBUTE_PRINTF_2;
171#endif
172
173#endif /* ! GCC_DIAGNOSTIC_CORE_H */
~auto_diagnostic_group()
Definition diagnostic-global-context.cc:850
auto_diagnostic_group()
Definition diagnostic-global-context.cc:843
auto_diagnostic_nesting_level()
Definition diagnostic-global-context.cc:857
~auto_diagnostic_nesting_level()
Definition diagnostic-global-context.cc:862
bool bool bool bool bool bool void void sorry_at(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
void internal_error(const char *,...) ATTRIBUTE_GCC_DIAG(1
void internal_error_no_backtrace(const char *,...) ATTRIBUTE_GCC_DIAG(1
bool bool bool void void error_n(location_t, unsigned HOST_WIDE_INT, const char *, const char *,...) ATTRIBUTE_GCC_DIAG(3
const char * trim_filename(const char *)
Definition errors.cc:112
void bool bool bool bool emit_diagnostic_valist_meta(enum diagnostics::kind, rich_location *, const diagnostics::metadata *, diagnostics::option_id, const char *, va_list *) ATTRIBUTE_GCC_DIAG(5
bool warning_at(location_t, diagnostics::option_id, const char *,...) ATTRIBUTE_GCC_DIAG(3
void bool bool bool emit_diagnostic_valist(enum diagnostics::kind, location_t, diagnostics::option_id, const char *, va_list *) ATTRIBUTE_GCC_DIAG(4
bool bool warning_n(location_t, diagnostics::option_id, unsigned HOST_WIDE_INT, const char *, const char *,...) ATTRIBUTE_GCC_DIAG(4
void void void void fatal_error(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
void verbatim(const char *,...) ATTRIBUTE_GCC_DIAG(1
bool bool bool void error(const char *,...) ATTRIBUTE_GCC_DIAG(1
bool bool bool warning_meta(rich_location *, const diagnostics::metadata &, diagnostics::option_id, const char *,...) ATTRIBUTE_GCC_DIAG(4
void void void error_meta(rich_location *, const diagnostics::metadata &, const char *,...) ATTRIBUTE_GCC_DIAG(3
void ATTRIBUTE_NORETURN
Definition diagnostic-core.h:76
void bool bool bool bool bool seen_error(void)
Definition diagnostic-global-context.cc:744
void bool emit_diagnostic(enum diagnostics::kind, location_t, diagnostics::option_id, const char *,...) ATTRIBUTE_GCC_DIAG(4
bool bool bool bool bool bool void sorry(const char *,...) ATTRIBUTE_GCC_DIAG(1
bool bool bool permerror(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
bool warning(diagnostics::option_id, const char *,...) ATTRIBUTE_GCC_DIAG(2
const char * progname
Definition errors.cc:36
bool pedwarn(location_t, diagnostics::option_id, const char *,...) ATTRIBUTE_GCC_DIAG(3
bool bool bool bool bool bool void void void void void inform_n(location_t, unsigned HOST_WIDE_INT, const char *, const char *,...) ATTRIBUTE_GCC_DIAG(3
#define ATTRIBUTE_GCC_DIAG(m, n)
Definition diagnostic-core.h:71
bool bool bool bool bool bool void void void inform(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
bool bool bool bool bool permerror_opt(location_t, diagnostics::option_id, const char *,...) ATTRIBUTE_GCC_DIAG(3
void error_at(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
void fnotice(FILE *file, const char *cmsgid,...)
Definition diagnostic-global-context.cc:822
Definition coretypes.h:167