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.
4 Copyright (C) 1998-2024 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
27/* Constants used to discriminate diagnostics. */
28typedef enum
29{
30#define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K,
31#include "diagnostic.def"
32#undef DEFINE_DIAGNOSTIC_KIND
34 /* This is used for tagging pragma pops in the diagnostic
35 classification history chain. */
36 DK_POP,
37 /* This is used internally to note that a diagnostic is enabled
38 without mandating any specific type. */
39 DK_ANY,
41
42/* RAII-style class for grouping related diagnostics. */
43
50
51/* RAII-style class for nesting hierarchical diagnostics.
52 Any diagnostics emitted within the lifetime of this object
53 will be treated as one level of nesting deeper than diagnostics
54 emitted outside the lifetime of the object. */
55
62
63/* Forward decl. */
64class diagnostic_metadata; /* See diagnostic-metadata.h. */
65
66/* A class to use for the ID of an option that controls
67 a particular diagnostic.
68 This is just a wrapper around "int", but better documents
69 the intent of the code. */
70
72{
74
75 diagnostic_option_id (int idx) : m_idx (idx) {}
76 /* Ideally we'd take an enum opt_code here, but we don't
77 want to depend on its decl. */
78
80 {
81 return m_idx == other.m_idx;
82 }
83
84 int m_idx;
85};
86
87extern const char *progname;
88
89extern const char *trim_filename (const char *);
91/* If we haven't already defined a front-end-specific diagnostics
92 style, use the generic one. */
93#ifndef GCC_DIAG_STYLE
94#define GCC_DIAG_STYLE __gcc_tdiag__
95#endif
96/* None of these functions are suitable for ATTRIBUTE_PRINTF, because
97 each language front end can extend them with its own set of format
98 specifiers. We must use custom format checks. */
99#if (CHECKING_P && GCC_VERSION >= 4001) || GCC_VERSION == BUILDING_GCC_VERSION
100#define ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
101#else
102#define ATTRIBUTE_GCC_DIAG(m, n) ATTRIBUTE_NONNULL(m)
103#endif
104extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
106extern void internal_error_no_backtrace (const char *, ...)
108/* Pass one of the OPT_W* from options.h as the first parameter. */
110 const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
111extern bool warning_n (location_t,
113 unsigned HOST_WIDE_INT,
114 const char *, const char *, ...)
116extern bool warning_n (rich_location *,
118 unsigned HOST_WIDE_INT,
119 const char *, const char *, ...)
121extern bool warning_at (location_t,
123 const char *, ...)
125extern bool warning_at (rich_location *,
127 const char *, ...)
129extern bool warning_meta (rich_location *,
130 const diagnostic_metadata &,
132 const char *, ...)
134extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
135extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *,
136 const char *, ...)
138extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
139extern void error_at (rich_location *, const char *, ...)
141extern void error_meta (rich_location *, const diagnostic_metadata &,
142 const char *, ...)
144extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
146/* Pass one of the OPT_W* from options.h as the second parameter. */
147extern bool pedwarn (location_t,
149 const char *, ...)
151extern bool pedwarn (rich_location *,
153 const char *, ...)
155extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
156extern bool permerror (rich_location *, const char *,
157 ...) ATTRIBUTE_GCC_DIAG(2,3);
158extern bool permerror_opt (location_t,
160 const char *, ...)
162extern bool permerror_opt (rich_location *,
164 const char *, ...)
166extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
167extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
168extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
169extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
170extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
171 const char *, ...)
173extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
175 location_t,
177 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
179 rich_location *,
181 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
183 location_t,
185 const char *, va_list *)
186 ATTRIBUTE_GCC_DIAG (4,0);
188 rich_location *,
189 const diagnostic_metadata *,
191 const char *,
192 va_list *) ATTRIBUTE_GCC_DIAG (5,0);
193extern bool seen_error (void);
194
195#ifdef BUFSIZ
196 /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and
197 therefore it can have ATTRIBUTE_PRINTF. */
198extern void fnotice (FILE *, const char *, ...)
199 ATTRIBUTE_PRINTF_2;
200#endif
201
202#endif /* ! GCC_DIAGNOSTIC_CORE_H */
Definition diagnostic-core.h:45
~auto_diagnostic_group()
Definition diagnostic-global-context.cc:574
auto_diagnostic_group()
Definition diagnostic-global-context.cc:567
Definition diagnostic-core.h:57
auto_diagnostic_nesting_level()
Definition diagnostic-global-context.cc:581
~auto_diagnostic_nesting_level()
Definition diagnostic-global-context.cc:586
Definition diagnostic-metadata.h:33
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 bool emit_diagnostic(diagnostic_t, location_t, diagnostic_option_id, const char *,...) ATTRIBUTE_GCC_DIAG(4
bool pedwarn(location_t, diagnostic_option_id, const char *,...) ATTRIBUTE_GCC_DIAG(3
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 diagnostic.cc:1548
bool bool bool bool bool permerror_opt(location_t, diagnostic_option_id, const char *,...) ATTRIBUTE_GCC_DIAG(3
void bool bool bool bool emit_diagnostic_valist_meta(diagnostic_t, rich_location *, const diagnostic_metadata *, diagnostic_option_id, const char *, va_list *) ATTRIBUTE_GCC_DIAG(5
bool bool warning_n(location_t, diagnostic_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 bool bool bool emit_diagnostic_valist(diagnostic_t, location_t, diagnostic_option_id, const char *, va_list *) ATTRIBUTE_GCC_DIAG(4
void verbatim(const char *,...) ATTRIBUTE_GCC_DIAG(1
bool bool bool void error(const char *,...) ATTRIBUTE_GCC_DIAG(1
void ATTRIBUTE_NORETURN
Definition diagnostic-core.h:105
void bool bool bool bool bool seen_error(void)
Definition diagnostic-global-context.cc:487
bool warning(diagnostic_option_id, const char *,...) ATTRIBUTE_GCC_DIAG(2
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
void void void error_meta(rich_location *, const diagnostic_metadata &, const char *,...) ATTRIBUTE_GCC_DIAG(3
const char * progname
Definition diagnostic.cc:73
diagnostic_t
Definition diagnostic-core.h:29
@ DK_LAST_DIAGNOSTIC_KIND
Definition diagnostic-core.h:90
@ DK_ANY
Definition diagnostic-core.h:96
@ DK_POP
Definition diagnostic-core.h:93
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:100
bool bool bool bool bool bool void void void inform(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
void error_at(location_t, const char *,...) ATTRIBUTE_GCC_DIAG(2
bool bool bool warning_meta(rich_location *, const diagnostic_metadata &, diagnostic_option_id, const char *,...) ATTRIBUTE_GCC_DIAG(4
bool warning_at(location_t, diagnostic_option_id, const char *,...) ATTRIBUTE_GCC_DIAG(3
void fnotice(FILE *file, const char *cmsgid,...)
Definition diagnostic-global-context.cc:546
Definition diagnostic-core.h:72
bool operator==(diagnostic_option_id other) const
Definition diagnostic-core.h:79
diagnostic_option_id()
Definition diagnostic-core.h:73
diagnostic_option_id(int idx)
Definition diagnostic-core.h:75
int m_idx
Definition diagnostic-core.h:84