libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / diagnostic-core.h
blob0fddf25403ce839e4adb5fac475fb76793e4ee53
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.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_DIAGNOSTIC_CORE_H
23 #define GCC_DIAGNOSTIC_CORE_H
25 #include "bversion.h"
27 /* Constants used to discriminate diagnostics. */
28 typedef enum
30 #define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K,
31 #include "diagnostic.def"
32 #undef DEFINE_DIAGNOSTIC_KIND
33 DK_LAST_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,
40 } diagnostic_t;
42 /* RAII-style class for grouping related diagnostics. */
44 class auto_diagnostic_group
46 public:
47 auto_diagnostic_group ();
48 ~auto_diagnostic_group ();
51 /* Forward decl. */
52 class diagnostic_metadata; /* See diagnostic-metadata.h. */
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. */
59 struct diagnostic_option_id
61 diagnostic_option_id () : m_idx (0) {}
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. */
67 bool operator== (diagnostic_option_id other) const
69 return m_idx == other.m_idx;
72 int m_idx;
75 extern const char *progname;
77 extern const char *trim_filename (const char *);
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
92 extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
93 ATTRIBUTE_NORETURN;
94 extern void internal_error_no_backtrace (const char *, ...)
95 ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN;
96 /* Pass one of the OPT_W* from options.h as the first parameter. */
97 extern bool warning (diagnostic_option_id,
98 const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
99 extern bool warning_n (location_t,
100 diagnostic_option_id,
101 unsigned HOST_WIDE_INT,
102 const char *, const char *, ...)
103 ATTRIBUTE_GCC_DIAG(4,6) ATTRIBUTE_GCC_DIAG(5,6);
104 extern bool warning_n (rich_location *,
105 diagnostic_option_id,
106 unsigned HOST_WIDE_INT,
107 const char *, const char *, ...)
108 ATTRIBUTE_GCC_DIAG(4, 6) ATTRIBUTE_GCC_DIAG(5, 6);
109 extern bool warning_at (location_t,
110 diagnostic_option_id,
111 const char *, ...)
112 ATTRIBUTE_GCC_DIAG(3,4);
113 extern bool warning_at (rich_location *,
114 diagnostic_option_id,
115 const char *, ...)
116 ATTRIBUTE_GCC_DIAG(3,4);
117 extern bool warning_meta (rich_location *,
118 const diagnostic_metadata &,
119 diagnostic_option_id,
120 const char *, ...)
121 ATTRIBUTE_GCC_DIAG(4,5);
122 extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
123 extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *,
124 const char *, ...)
125 ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5);
126 extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
127 extern void error_at (rich_location *, const char *, ...)
128 ATTRIBUTE_GCC_DIAG(2,3);
129 extern void error_meta (rich_location *, const diagnostic_metadata &,
130 const char *, ...)
131 ATTRIBUTE_GCC_DIAG(3,4);
132 extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
133 ATTRIBUTE_NORETURN;
134 /* Pass one of the OPT_W* from options.h as the second parameter. */
135 extern bool pedwarn (location_t,
136 diagnostic_option_id,
137 const char *, ...)
138 ATTRIBUTE_GCC_DIAG(3,4);
139 extern bool pedwarn (rich_location *,
140 diagnostic_option_id,
141 const char *, ...)
142 ATTRIBUTE_GCC_DIAG(3,4);
143 extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
144 extern bool permerror (rich_location *, const char *,
145 ...) ATTRIBUTE_GCC_DIAG(2,3);
146 extern bool permerror_opt (location_t,
147 diagnostic_option_id,
148 const char *, ...)
149 ATTRIBUTE_GCC_DIAG(3,4);
150 extern bool permerror_opt (rich_location *,
151 diagnostic_option_id,
152 const char *, ...)
153 ATTRIBUTE_GCC_DIAG(3,4);
154 extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
155 extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
156 extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
157 extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
158 extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
159 const char *, ...)
160 ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5);
161 extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
162 extern bool emit_diagnostic (diagnostic_t,
163 location_t,
164 diagnostic_option_id,
165 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
166 extern bool emit_diagnostic (diagnostic_t,
167 rich_location *,
168 diagnostic_option_id,
169 const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
170 extern bool emit_diagnostic_valist (diagnostic_t,
171 location_t,
172 diagnostic_option_id,
173 const char *, va_list *)
174 ATTRIBUTE_GCC_DIAG (4,0);
175 extern bool emit_diagnostic_valist_meta (diagnostic_t,
176 rich_location *,
177 const diagnostic_metadata *,
178 diagnostic_option_id,
179 const char *,
180 va_list *) ATTRIBUTE_GCC_DIAG (5,0);
181 extern bool seen_error (void);
183 #ifdef BUFSIZ
184 /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and
185 therefore it can have ATTRIBUTE_PRINTF. */
186 extern void fnotice (FILE *, const char *, ...)
187 ATTRIBUTE_PRINTF_2;
188 #endif
190 #endif /* ! GCC_DIAGNOSTIC_CORE_H */