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/* Forward decl. */
52class diagnostic_metadata; /* See diagnostic-metadata.h. */
53
54/* A class to use for the ID of an option that controls
55 a particular diagnostic.
56 This is just a wrapper around "int", but better documents
57 the intent of the code. */
58
60{
62
63 diagnostic_option_id (int idx) : m_idx (idx) {}
64 /* Ideally we'd take an enum opt_code here, but we don't
65 want to depend on its decl. */
66
68 {
69 return m_idx == other.m_idx;
70 }
71
72 int m_idx;
73};
74
75extern const char *progname;
76
77extern const char *trim_filename (const char *);
78
79/* If we haven't already defined a front-end-specific diagnostics
80 style, use the generic one. */
81#ifndef GCC_DIAG_STYLE
82#define GCC_DIAG_STYLE __gcc_tdiag__
83#endif
84/* None of these functions are suitable for ATTRIBUTE_PRINTF, because
85 each language front end can extend them with its own set of format
86 specifiers. We must use custom format checks. */
87#if (CHECKING_P && GCC_VERSION >= 4001) || GCC_VERSION == BUILDING_GCC_VERSION
88#define ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
89#else
90#define ATTRIBUTE_GCC_DIAG(m, n) ATTRIBUTE_NONNULL(m)
91#endif
92extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
94extern void internal_error_no_backtrace (const char *, ...)
96/* Pass one of the OPT_W* from options.h as the first parameter. */
98 const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
99extern bool warning_n (location_t,
101 unsigned HOST_WIDE_INT,
102 const char *, const char *, ...)
104extern bool warning_n (rich_location *,
106 unsigned HOST_WIDE_INT,
107 const char *, const char *, ...)
109extern bool warning_at (location_t,
111 const char *, ...)
113extern bool warning_at (rich_location *,
115 const char *, ...)
117extern bool warning_meta (rich_location *,
118 const diagnostic_metadata &,
120 const char *, ...)
122extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
123extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *,
124 const char *, ...)
126extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
127extern void error_at (rich_location *, const char *, ...)
129extern void error_meta (rich_location *, const diagnostic_metadata &,
130 const char *, ...)
132extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
134/* Pass one of the OPT_W* from options.h as the second parameter. */
135extern bool pedwarn (location_t,
137 const char *, ...)
139extern bool pedwarn (rich_location *,
141 const char *, ...)
143extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
144extern bool permerror (rich_location *, const char *,
145 ...) ATTRIBUTE_GCC_DIAG(2,3);
146extern bool permerror_opt (location_t,
148 const char *, ...)
150extern bool permerror_opt (rich_location *,
152 const char *, ...)
154extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
155extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
156extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
157extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
158extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
159 const char *, ...)
161extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
163 location_t,
165 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
167 rich_location *,
169 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
171 location_t,
173 const char *, va_list *)
174 ATTRIBUTE_GCC_DIAG (4,0);
176 rich_location *,
177 const diagnostic_metadata *,
179 const char *,
180 va_list *) ATTRIBUTE_GCC_DIAG (5,0);
181extern bool seen_error (void);
182
183#ifdef BUFSIZ
184 /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and
185 therefore it can have ATTRIBUTE_PRINTF. */
186extern void fnotice (FILE *, const char *, ...)
187 ATTRIBUTE_PRINTF_2;
188#endif
189
190#endif /* ! GCC_DIAGNOSTIC_CORE_H */
Definition diagnostic-core.h:45
~auto_diagnostic_group()
Definition diagnostic-global-context.cc:576
auto_diagnostic_group()
Definition diagnostic-global-context.cc:569
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:1430
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:93
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:72
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:88
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:60
bool operator==(diagnostic_option_id other) const
Definition diagnostic-core.h:67
diagnostic_option_id()
Definition diagnostic-core.h:61
diagnostic_option_id(int idx)
Definition diagnostic-core.h:63
int m_idx
Definition diagnostic-core.h:72