GCC Middle and Back End API Reference
selftest-diagnostic.h
Go to the documentation of this file.
1/* Selftest support for diagnostics.
2 Copyright (C) 2016-2025 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_SELFTEST_DIAGNOSTIC_H
21#define GCC_SELFTEST_DIAGNOSTIC_H
22
23/* The selftest code should entirely disappear in a production
24 configuration, hence we guard all of it with #if CHECKING_P. */
25
26#if CHECKING_P
27
28namespace selftest {
29
30/* Convenience subclass of diagnostic_context for testing
31 the diagnostic subsystem. */
32
33class test_diagnostic_context : public diagnostic_context
34{
35 public:
36 test_diagnostic_context ();
37 ~test_diagnostic_context ();
38
39 /* Implementation of diagnostic_start_span_fn, hiding the
40 real filename (to avoid printing the names of tempfiles). */
41 static void
42 start_span_cb (const diagnostic_location_print_policy &,
43 pretty_printer *,
44 expanded_location exploc);
45
46 /* Report a diagnostic to this context. For a selftest, this
47 should only be called on a context that uses a non-standard formatter
48 that e.g. gathers the results in memory, rather than emits to stderr. */
49 bool
50 report (diagnostic_t kind,
51 rich_location &richloc,
52 const diagnostic_metadata *metadata,
53 int option,
54 const char * fmt, ...) ATTRIBUTE_GCC_DIAG(6,7);
55
56 const char *test_show_locus (rich_location &richloc);
57};
58
59} // namespace selftest
60
61#endif /* #if CHECKING_P */
62
63#endif /* GCC_SELFTEST_DIAGNOSTIC_H */
diagnostic_t
Definition diagnostic-core.h:29
#define ATTRIBUTE_GCC_DIAG(m, n)
Definition diagnostic-core.h:100
static options_p option(options_p prev)
Definition gengtype-parse.cc:547
Definition dump-context.h:31