GCC Middle and Back End API Reference
diagnostic-global-context.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "intl.h"
#include "diagnostic.h"
#include "diagnostics/sink.h"
#include "diagnostics/logging.h"
Include dependency graph for diagnostic-global-context.cc:

Typedefs

using log_function_params = diagnostics::logging::log_function_params
using auto_inc_log_depth = diagnostics::logging::auto_inc_depth

Functions

void verbatim (const char *gmsgid,...)
bool emit_diagnostic (enum diagnostics::kind kind, location_t location, diagnostics::option_id option_id, const char *gmsgid,...)
bool emit_diagnostic (enum diagnostics::kind kind, rich_location *richloc, diagnostics::option_id option_id, const char *gmsgid,...)
bool emit_diagnostic_valist (enum diagnostics::kind kind, location_t location, diagnostics::option_id option_id, const char *gmsgid, va_list *ap)
bool emit_diagnostic_valist_meta (enum diagnostics::kind kind, rich_location *richloc, const diagnostics::metadata *metadata, diagnostics::option_id option_id, const char *gmsgid, va_list *ap)
void inform (location_t location, const char *gmsgid,...)
void inform (rich_location *richloc, const char *gmsgid,...)
void inform_n (location_t location, unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid,...)
bool warning (diagnostics::option_id option_id, const char *gmsgid,...)
bool warning_at (location_t location, diagnostics::option_id option_id, const char *gmsgid,...)
bool warning_at (rich_location *richloc, diagnostics::option_id option_id, const char *gmsgid,...)
bool warning_meta (rich_location *richloc, const diagnostics::metadata &metadata, diagnostics::option_id option_id, const char *gmsgid,...)
bool warning_n (rich_location *richloc, diagnostics::option_id option_id, unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid,...)
bool warning_n (location_t location, diagnostics::option_id option_id, unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid,...)
bool pedwarn (location_t location, diagnostics::option_id option_id, const char *gmsgid,...)
bool pedwarn (rich_location *richloc, diagnostics::option_id option_id, const char *gmsgid,...)
bool permerror (location_t location, const char *gmsgid,...)
bool permerror (rich_location *richloc, const char *gmsgid,...)
bool permerror_opt (location_t location, diagnostics::option_id option_id, const char *gmsgid,...)
bool permerror_opt (rich_location *richloc, diagnostics::option_id option_id, const char *gmsgid,...)
void error (const char *gmsgid,...)
void error_n (location_t location, unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid,...)
void error_at (location_t loc, const char *gmsgid,...)
void error_at (rich_location *richloc, const char *gmsgid,...)
void error_meta (rich_location *richloc, const diagnostics::metadata &metadata, const char *gmsgid,...)
void sorry (const char *gmsgid,...)
void sorry_at (location_t loc, const char *gmsgid,...)
bool seen_error (void)
void fatal_error (location_t loc, const char *gmsgid,...)
void internal_error (const char *gmsgid,...)
void internal_error_no_backtrace (const char *gmsgid,...)
void fnotice (FILE *file, const char *cmsgid,...)

Variables

static diagnostics::context global_diagnostic_context
diagnostics::contextglobal_dc = &global_diagnostic_context

Typedef Documentation

◆ auto_inc_log_depth

◆ log_function_params

Function Documentation

◆ emit_diagnostic() [1/2]

bool emit_diagnostic ( enum diagnostics::kind kind,
location_t location,
diagnostics::option_id option_id,
const char * gmsgid,
... )

◆ emit_diagnostic() [2/2]

◆ emit_diagnostic_valist()

bool emit_diagnostic_valist ( enum diagnostics::kind kind,
location_t location,
diagnostics::option_id option_id,
const char * gmsgid,
va_list * ap )

◆ emit_diagnostic_valist_meta()

bool emit_diagnostic_valist_meta ( enum diagnostics::kind kind,
rich_location * richloc,
const diagnostics::metadata * metadata,
diagnostics::option_id option_id,
const char * gmsgid,
va_list * ap )

◆ error()

void error ( const char * gmsgid,
... )
A hard error: the code is definitely ill-formed, and an object file
will not be produced.   

References ap, global_dc, input_location, line_table, and diagnostics::logging::log_function_params::log_param_string().

◆ error_at() [1/2]

void error_at ( location_t loc,
const char * gmsgid,
... )

◆ error_at() [2/2]

void error_at ( rich_location * richloc,
const char * gmsgid,
... )

◆ error_meta()

void error_meta ( rich_location * richloc,
const diagnostics::metadata & metadata,
const char * gmsgid,
... )

◆ error_n()

void error_n ( location_t location,
unsigned HOST_WIDE_INT n,
const char * singular_gmsgid,
const char * plural_gmsgid,
... )
A hard error: the code is definitely ill-formed, and an object file
will not be produced.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), and diagnostics::logging::log_function_params::log_params_n_gmsgids().

◆ fatal_error()

void fatal_error ( location_t loc,
const char * gmsgid,
... )
An error which is severe enough that we make no attempt to
continue.  Do not use this for internal consistency checks; that's
internal_error.  Use of this function should be rare.   

References ap, gcc_unreachable, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), and diagnostics::logging::log_function_params::log_param_string().

◆ fnotice()

◆ inform() [1/2]

void inform ( location_t location,
const char * gmsgid,
... )
An informative note at LOCATION.  Use this for additional details on an error
message.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), and diagnostics::logging::log_function_params::log_param_string().

◆ inform() [2/2]

void inform ( rich_location * richloc,
const char * gmsgid,
... )

◆ inform_n()

void inform_n ( location_t location,
unsigned HOST_WIDE_INT n,
const char * singular_gmsgid,
const char * plural_gmsgid,
... )
An informative note at LOCATION.  Use this for additional details on an
error message.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), and diagnostics::logging::log_function_params::log_params_n_gmsgids().

◆ internal_error()

void internal_error ( const char * gmsgid,
... )
An internal consistency check has failed.  We make no attempt to
continue.   

References ap, gcc_unreachable, global_dc, input_location, line_table, and diagnostics::logging::log_function_params::log_param_string().

◆ internal_error_no_backtrace()

void internal_error_no_backtrace ( const char * gmsgid,
... )
Like internal_error, but no backtrace will be printed.  Used when
the internal error does not happen at the current location, but happened
somewhere else.   

References ap, gcc_unreachable, global_dc, input_location, line_table, and diagnostics::logging::log_function_params::log_param_string().

◆ pedwarn() [1/2]

bool pedwarn ( location_t location,
diagnostics::option_id option_id,
const char * gmsgid,
... )
A "pedantic" warning at LOCATION: issues a warning unless
-pedantic-errors was given on the command line, in which case it
issues an error.  Use this for diagnostics required by the relevant
language standard, if you have chosen not to make them errors.

Note that these diagnostics are issued independent of the setting
of the -Wpedantic command-line switch.  To get a warning enabled
only with that switch, use either "if (pedantic) pedwarn
(OPT_Wpedantic,...)" or just "pedwarn (OPT_Wpedantic,..)".  To get a
pedwarn independently of the -Wpedantic switch use "pedwarn (0,...)".

Returns true if the warning was printed, false if it was inhibited.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), diagnostics::logging::log_function_params::log_param_option_id(), and diagnostics::logging::log_function_params::log_param_string().

◆ pedwarn() [2/2]

◆ permerror() [1/2]

bool permerror ( location_t location,
const char * gmsgid,
... )
A "permissive" error at LOCATION: issues an error unless
-fpermissive was given on the command line, in which case it issues
a warning.  Use this for things that really should be errors but we
want to support legacy code.

Returns true if the warning was printed, false if it was inhibited.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), and diagnostics::logging::log_function_params::log_param_string().

◆ permerror() [2/2]

bool permerror ( rich_location * richloc,
const char * gmsgid,
... )

◆ permerror_opt() [1/2]

bool permerror_opt ( location_t location,
diagnostics::option_id option_id,
const char * gmsgid,
... )
Similar to the above, but controlled by a flag other than -fpermissive.
As above, an error by default or a warning with -fpermissive, but this
diagnostic can also be downgraded by -Wno-error=opt.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), diagnostics::logging::log_function_params::log_param_option_id(), and diagnostics::logging::log_function_params::log_param_string().

◆ permerror_opt() [2/2]

◆ seen_error()

◆ sorry()

void sorry ( const char * gmsgid,
... )
"Sorry, not implemented."  Use for a language feature which is
required by the relevant specification but not implemented by GCC.
An object file will not be produced.   

References ap, global_dc, input_location, line_table, and diagnostics::logging::log_function_params::log_param_string().

◆ sorry_at()

void sorry_at ( location_t loc,
const char * gmsgid,
... )

◆ verbatim()

void verbatim ( const char * gmsgid,
... )
Standard error reporting routines in increasing order of severity.   
Text to be emitted verbatim to the error message stream; this
produces no prefix and disables line-wrapping.  Use rarely.
It is ignored for machine-readable output formats.   

References _, ap, errno, global_dc, and diagnostics::logging::log_function_params::log_param_string().

◆ warning()

bool warning ( diagnostics::option_id option_id,
const char * gmsgid,
... )
A warning at INPUT_LOCATION.  Use this for code which is correct according
to the relevant language specification but is likely to be buggy anyway.
Returns true if the warning was printed, false if it was inhibited.   

References ap, global_dc, input_location, line_table, diagnostics::logging::log_function_params::log_param_option_id(), and diagnostics::logging::log_function_params::log_param_string().

◆ warning_at() [1/2]

bool warning_at ( location_t location,
diagnostics::option_id option_id,
const char * gmsgid,
... )
A warning at LOCATION.  Use this for code which is correct according to the
relevant language specification but is likely to be buggy anyway.
Returns true if the warning was printed, false if it was inhibited.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), diagnostics::logging::log_function_params::log_param_option_id(), and diagnostics::logging::log_function_params::log_param_string().

◆ warning_at() [2/2]

◆ warning_meta()

bool warning_meta ( rich_location * richloc,
const diagnostics::metadata & metadata,
diagnostics::option_id option_id,
const char * gmsgid,
... )

◆ warning_n() [1/2]

bool warning_n ( location_t location,
diagnostics::option_id option_id,
unsigned HOST_WIDE_INT n,
const char * singular_gmsgid,
const char * plural_gmsgid,
... )
A warning at LOCATION.  Use this for code which is correct according to the
relevant language specification but is likely to be buggy anyway.
Returns true if the warning was printed, false if it was inhibited.   

References ap, global_dc, line_table, diagnostics::logging::log_function_params::log_param_location_t(), diagnostics::logging::log_function_params::log_param_option_id(), and diagnostics::logging::log_function_params::log_params_n_gmsgids().

◆ warning_n() [2/2]

bool warning_n ( rich_location * richloc,
diagnostics::option_id option_id,
unsigned HOST_WIDE_INT n,
const char * singular_gmsgid,
const char * plural_gmsgid,
... )

Variable Documentation

◆ global_dc

This diagnostics::context is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
and similar functions.   

Referenced by gcc_rich_location::add_fixit_insert_formatted(), announce_function(), attr_access::array_as_string(), asm_show_source(), auto_diagnostic_group::auto_diagnostic_group(), auto_diagnostic_nesting_level::auto_diagnostic_nesting_level(), auto_override_urlifier::auto_override_urlifier(), diagnostic_for_asm(), do_self_spec(), driver_handle_option(), text_art::dump_to_file(), emit_diagnostic(), emit_diagnostic(), emit_diagnostic_valist(), emit_diagnostic_valist_meta(), format_string_diagnostic_t::emit_warning_n_va(), error(), error_at(), error_at(), error_meta(), error_n(), escaped_string::escape(), fancy_abort(), fatal_error(), driver::finalize(), fnotice(), general_init(), driver::global_initializations(), inform(), inform(), inform_n(), init_asm_output(), init_options_once(), internal_error(), internal_error_function(), internal_error_no_backtrace(), lang_handle_option(), main(), main(), main(), toplev::main(), lazy_diagnostic_context_path::make_inner_path(), option_unspecified_p(), pedwarn(), pedwarn(), permerror(), permerror(), permerror_opt(), permerror_opt(), print_lto_docs_link(), process_command(), process_options(), run_gcc(), sorry(), sorry_at(), target_handle_option(), tree_dump_pretty_printer::tree_dump_pretty_printer(), verbatim(), warning(), warning_at(), warning_at(), warning_enabled_at(), warning_meta(), warning_n(), warning_n(), auto_diagnostic_group::~auto_diagnostic_group(), auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level(), and auto_override_urlifier::~auto_override_urlifier().

◆ global_diagnostic_context

diagnostics::context global_diagnostic_context
static
Language-independent diagnostic subroutines that implicitly use global_dc.
   Copyright (C) 1999-2025 Free Software Foundation, Inc.
   Contributed by Gabriel Dos Reis <gdr@codesourcery.com>

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
This file implements the parts of the language independent aspect
of diagnostic messages that implicitly use global_dc.   
A diagnostics::context surrogate for stderr.