/* C/ObjC/C++ command line option handling.
- Copyright (C) 2002-2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2020 Free Software Foundation, Inc.
Contributed by Neil Booth.
This file is part of GCC.
static void set_std_cxx11 (int);
static void set_std_cxx14 (int);
static void set_std_cxx17 (int);
-static void set_std_cxx2a (int);
+static void set_std_cxx20 (int);
static void set_std_c89 (int, int);
static void set_std_c99 (int);
static void set_std_c11 (int);
/* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
static void
c_diagnostic_finalizer (diagnostic_context *context,
- diagnostic_info *diagnostic)
+ diagnostic_info *diagnostic,
+ diagnostic_t)
{
+ char *saved_prefix = pp_take_prefix (context->printer);
+ pp_set_prefix (context->printer, NULL);
+ pp_newline (context->printer);
diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
/* By default print macro expansion contexts in the diagnostic
finalizer -- for tokens resulting from macro expansion. */
virt_loc_aware_diagnostic_finalizer (context, diagnostic);
- pp_destroy_prefix (context->printer);
+ pp_set_prefix (context->printer, saved_prefix);
pp_flush (context->printer);
}
}
}
- /* Set C++ standard to C++14 if not specified on the command line. */
+ /* Set C++ standard to C++17 if not specified on the command line. */
if (c_dialect_cxx ())
- set_std_cxx14 (/*ISO*/false);
+ set_std_cxx17 (/*ISO*/false);
global_dc->colorize_source_p = true;
}
else
{
if (quote_chain_split)
- error ("-I- specified twice");
+ error ("%<-I-%> specified twice");
quote_chain_split = true;
split_quote_chain ();
- inform (input_location, "obsolete option -I- used, please use -iquote instead");
+ inform (input_location, "obsolete option %<-I-%> used, "
+ "please use %<-iquote%> instead");
}
break;
cpp_opts->extended_identifiers = value;
break;
+ case OPT_fmax_include_depth_:
+ cpp_opts->max_include_depth = value;
+ break;
+
case OPT_foperator_names:
cpp_opts->operator_names = value;
break;
cpp_opts->track_macro_expansion = 2;
break;
- case OPT_frepo:
- flag_use_repository = value;
- if (value)
- flag_implicit_templates = 0;
- break;
-
- case OPT_ftabstop_:
- /* It is documented that we silently ignore silly values. */
- if (value >= 1 && value <= 100)
- cpp_opts->tabstop = value;
- break;
-
case OPT_fexec_charset_:
cpp_opts->narrow_charset = arg;
break;
set_std_cxx17 (code == OPT_std_c__17 /* ISO */);
break;
- case OPT_std_c__2a:
- case OPT_std_gnu__2a:
+ case OPT_std_c__20:
+ case OPT_std_gnu__20:
if (!preprocessing_asm_p)
- set_std_cxx2a (code == OPT_std_c__2a /* ISO */);
+ set_std_cxx20 (code == OPT_std_c__20 /* ISO */);
break;
case OPT_std_c90:
bool
c_common_post_options (const char **pfilename)
{
- struct cpp_callbacks *cb;
-
/* Canonicalize the input and output filenames. */
if (in_fnames == NULL)
{
support. */
if (c_dialect_cxx ())
{
- if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
- sorry ("-fexcess-precision=standard for C++");
- flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
+ if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
+ sorry ("%<-fexcess-precision=standard%> for C++");
+ flag_excess_precision = EXCESS_PRECISION_FAST;
}
- else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
- flag_excess_precision_cmdline = (flag_iso
- ? EXCESS_PRECISION_STANDARD
- : EXCESS_PRECISION_FAST);
+ else if (flag_excess_precision == EXCESS_PRECISION_DEFAULT)
+ flag_excess_precision = (flag_iso ? EXCESS_PRECISION_STANDARD
+ : EXCESS_PRECISION_FAST);
/* ISO C restricts floating-point expression contraction to within
source-language expressions (-ffp-contract=on, currently an alias
else
flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_C11;
+ /* C2X Annex F does not permit certain built-in functions to raise
+ "inexact". */
+ if (flag_isoc2x)
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ flag_fp_int_builtin_inexact, 0);
+
/* By default we use C99 inline semantics in GNU99 or C99 mode. C99
inline semantics are not supported in GNU89 or C89 mode. */
if (flag_gnu89_inline == -1)
flag_gnu89_inline = !flag_isoc99;
else if (!flag_gnu89_inline && !flag_isoc99)
- error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
+ error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
/* Default to ObjC sjlj exception handling if NeXT runtime. */
if (flag_objc_sjlj_exceptions < 0)
/* If -ffreestanding, -fno-hosted or -fno-builtin then disable
pattern recognition. */
- if (!global_options_set.x_flag_tree_loop_distribute_patterns
- && flag_no_builtin)
- flag_tree_loop_distribute_patterns = 0;
+ if (flag_no_builtin)
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ flag_tree_loop_distribute_patterns, 0);
/* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
It is never enabled in C++, as the minimum limit is not normative
if (!warn_format)
{
warning (OPT_Wformat_y2k,
- "-Wformat-y2k ignored without -Wformat");
+ "%<-Wformat-y2k%> ignored without %<-Wformat%>");
warning (OPT_Wformat_extra_args,
- "-Wformat-extra-args ignored without -Wformat");
+ "%<-Wformat-extra-args%> ignored without %<-Wformat%>");
warning (OPT_Wformat_zero_length,
- "-Wformat-zero-length ignored without -Wformat");
+ "%<-Wformat-zero-length%> ignored without %<-Wformat%>");
warning (OPT_Wformat_nonliteral,
- "-Wformat-nonliteral ignored without -Wformat");
+ "%<-Wformat-nonliteral%> ignored without %<-Wformat%>");
warning (OPT_Wformat_contains_nul,
- "-Wformat-contains-nul ignored without -Wformat");
+ "%<-Wformat-contains-nul%> ignored without %<-Wformat%>");
warning (OPT_Wformat_security,
- "-Wformat-security ignored without -Wformat");
+ "%<-Wformat-security%> ignored without %<-Wformat%>");
}
/* -Wimplicit-function-declaration is enabled by default for C99. */
if (warn_implicit_int == -1)
warn_implicit_int = flag_isoc99;
+ /* -Wold-style-definition is enabled by default for C2X. */
+ if (warn_old_style_definition == -1)
+ warn_old_style_definition = flag_isoc2x;
+
/* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
if (warn_shift_overflow == -1)
warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
&& (cxx_dialect >= cxx11 || flag_isoc99));
/* -Wregister is enabled by default in C++17. */
- if (!global_options_set.x_warn_register)
- warn_register = cxx_dialect >= cxx17;
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_register,
+ cxx_dialect >= cxx17);
+
+ /* -Wcomma-subscript is enabled by default in C++20. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ warn_comma_subscript,
+ cxx_dialect >= cxx20 && warn_deprecated);
+
+ /* -Wvolatile is enabled by default in C++20. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_volatile,
+ cxx_dialect >= cxx20 && warn_deprecated);
+
+ /* -Wdeprecated-enum-enum-conversion is enabled by default in C++20. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ warn_deprecated_enum_enum_conv,
+ cxx_dialect >= cxx20 && warn_deprecated);
+
+ /* -Wdeprecated-enum-float-conversion is enabled by default in C++20. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ warn_deprecated_enum_float_conv,
+ cxx_dialect >= cxx20 && warn_deprecated);
/* Declone C++ 'structors if -Os. */
if (flag_declone_ctor_dtor == -1)
/* Change flag_abi_version to be the actual current ABI level, for the
benefit of c_cpp_builtins, and to make comparison simpler. */
- const int latest_abi_version = 13;
+ const int latest_abi_version = 15;
/* Generate compatibility aliases for ABI v11 (7.1) by default. */
const int abi_compat_default = 11;
if (flag_abi_version == latest_abi_version)
{
auto_diagnostic_group d;
- if (warning (OPT_Wabi, "-Wabi won't warn about anything"))
+ if (warning (OPT_Wabi, "%<-Wabi%> won%'t warn about anything"))
{
- inform (input_location, "-Wabi warns about differences "
+ inform (input_location, "%<-Wabi%> warns about differences "
"from the most up-to-date ABI, which is also used "
"by default");
- inform (input_location, "use e.g. -Wabi=11 to warn about "
+ inform (input_location, "use e.g. %<-Wabi=11%> to warn about "
"changes from GCC 7");
}
flag_abi_compat_version = abi_compat_default;
/* By default, enable the new inheriting constructor semantics along with ABI
11. New and old should coexist fine, but it is a change in what
artificial symbols are generated. */
- if (!global_options_set.x_flag_new_inheriting_ctors)
- flag_new_inheriting_ctors = abi_version_at_least (11);
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ flag_new_inheriting_ctors,
+ abi_version_at_least (11));
/* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
- if (!global_options_set.x_flag_new_ttp)
- flag_new_ttp = (cxx_dialect >= cxx17);
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_new_ttp,
+ cxx_dialect >= cxx17);
+
+ /* C++11 guarantees forward progress. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_finite_loops,
+ optimize >= 2 && cxx_dialect >= cxx11);
if (cxx_dialect >= cxx11)
{
if (flag_sized_deallocation == -1)
flag_sized_deallocation = (cxx_dialect >= cxx14);
+ /* char8_t support is new in C++20. */
+ if (flag_char8_t == -1)
+ flag_char8_t = (cxx_dialect >= cxx20);
+
if (flag_extern_tls_init)
{
if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
if (warn_return_type == -1 && c_dialect_cxx ())
warn_return_type = 1;
+ /* C++20 is the final version of concepts. We still use -fconcepts
+ to know when concepts are enabled. Note that -fconcepts-ts can
+ be used to include additional features, although modified to
+ work with the standard. */
+ if (cxx_dialect >= cxx20 || flag_concepts_ts)
+ flag_concepts = 1;
+ else if (flag_concepts)
+ /* For -std=c++17 -fconcepts, imply -fconcepts-ts. */
+ flag_concepts_ts = 1;
+
if (num_in_fnames > 1)
- error ("too many filenames given. Type %s --help for usage",
- progname);
+ error ("too many filenames given; type %<%s %s%> for usage",
+ progname, "--help");
if (flag_preprocess_only)
{
debug formats we warn here and refuse to load any PCH files. */
if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
warning (OPT_Wdeprecated,
- "the \"%s\" debug format cannot be used with "
+ "the %qs debug format cannot be used with "
"pre-compiled headers", debug_type_names[write_symbols]);
}
else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
input_location = UNKNOWN_LOCATION;
}
- cb = cpp_get_callbacks (parse_in);
+ struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
cb->file_change = cb_file_change;
cb->dir_change = cb_dir_change;
+ if (lang_hooks.preprocess_options)
+ lang_hooks.preprocess_options (parse_in);
cpp_post_options (parse_in);
init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
input_location = UNKNOWN_LOCATION;
*pfilename = this_input_filename
- = cpp_read_main_file (parse_in, in_fnames[0]);
+ = cpp_read_main_file (parse_in, in_fnames[0],
+ /* We'll inject preamble pieces if this is
+ not preprocessed. */
+ !cpp_opts->preprocessed);
+
/* Don't do any compilation or preprocessing if there is no input file. */
if (this_input_filename == NULL)
{
static void
handle_deferred_opts (void)
{
- size_t i;
- struct deps *deps;
-
/* Avoid allocating the deps buffer if we don't need it.
(This flag may be true without there having been -MT or -MQ
options, but we'll still need the deps buffer.) */
if (!deps_seen)
return;
- deps = cpp_get_deps (parse_in);
-
- for (i = 0; i < deferred_count; i++)
- {
- struct deferred_opt *opt = &deferred_opts[i];
+ if (mkdeps *deps = cpp_get_deps (parse_in))
+ for (unsigned i = 0; i < deferred_count; i++)
+ {
+ struct deferred_opt *opt = &deferred_opts[i];
- if (opt->code == OPT_MT || opt->code == OPT_MQ)
- deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
- }
+ if (opt->code == OPT_MT || opt->code == OPT_MQ)
+ deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
+ }
}
/* These settings are appropriate for GCC, but not necessarily so for
/* If we don't know what style of dependencies to output, complain
if any other dependency switches have been given. */
if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
- error ("to generate dependencies you must specify either -M or -MM");
+ error ("to generate dependencies you must specify either %<-M%> "
+ "or %<-MM%>");
/* -dM and dependencies suppress normal output; do it here so that
the last -d[MDN] switch overrides earlier ones. */
flag_no_line_commands = 1;
}
else if (cpp_opts->deps.missing_files)
- error ("-MG may only be used with -M or -MM");
+ error ("%<-MG%> may only be used with %<-M%> or %<-MM%>");
cpp_opts->unsigned_char = !flag_signed_char;
cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
if (cpp_opts->directives_only)
{
if (cpp_warn_unused_macros)
- error ("-fdirectives-only is incompatible with -Wunused_macros");
+ error ("%<-fdirectives-only%> is incompatible "
+ "with %<-Wunused-macros%>");
if (cpp_opts->traditional)
- error ("-fdirectives-only is incompatible with -traditional");
+ error ("%<-fdirectives-only%> is incompatible with %<-traditional%>");
}
}
= linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
_("<built-in>"), 0));
cb_file_change (parse_in, bltin_map);
+ linemap_line_start (line_table, 0, 1);
/* Make sure all of the builtins about to be declared have
BUILTINS_LOCATION has their location_t. */
= linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
_("<command-line>"), 0));
cb_file_change (parse_in, cmd_map);
+ linemap_line_start (line_table, 0, 1);
/* All command line defines must have the same location. */
- cpp_force_token_locations (parse_in, cmd_map->start_location);
+ cpp_force_token_locations (parse_in, line_table->highest_line);
for (size_t i = 0; i < deferred_count; i++)
{
struct deferred_opt *opt = &deferred_opts[i];
cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
/* Restore the line map back to the main file. */
if (!cpp_opts->preprocessed)
- cpp_change_file (parse_in, LC_RENAME, this_input_filename);
+ {
+ cpp_change_file (parse_in, LC_RENAME, this_input_filename);
+ if (lang_hooks.preprocess_main_file)
+ /* We're starting the main file. Inform the FE of that. */
+ lang_hooks.preprocess_main_file
+ (parse_in, line_table, LINEMAPS_LAST_ORDINARY_MAP (line_table));
+ }
/* Set this here so the client can change the option if it wishes,
and after stacking the main file so we don't trace the main file. */
/* File change callback. Has to handle -include files. */
static void
-cb_file_change (cpp_reader * ARG_UNUSED (pfile),
- const line_map_ordinary *new_map)
+cb_file_change (cpp_reader *reader, const line_map_ordinary *new_map)
{
if (flag_preprocess_only)
pp_file_change (new_map);
else
fe_file_change (new_map);
+ if (new_map && cpp_opts->preprocessed
+ && lang_hooks.preprocess_main_file && MAIN_FILE_P (new_map)
+ && ORDINARY_MAP_STARTING_LINE_NUMBER (new_map))
+ /* We're starting the main file. Inform the FE of that. */
+ lang_hooks.preprocess_main_file (reader, line_table, new_map);
+
if (new_map
&& (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
{
lang_hooks.name = "GNU C++17";
}
-/* Set the C++ 202a draft standard (without GNU extensions if ISO). */
+/* Set the C++ 2020 standard (without GNU extensions if ISO). */
static void
-set_std_cxx2a (int iso)
+set_std_cxx20 (int iso)
{
- cpp_set_lang (parse_in, iso ? CLK_CXX2A: CLK_GNUCXX2A);
+ cpp_set_lang (parse_in, iso ? CLK_CXX20: CLK_GNUCXX20);
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
flag_iso = iso;
flag_isoc94 = 1;
flag_isoc99 = 1;
flag_isoc11 = 1;
- cxx_dialect = cxx2a;
- lang_hooks.name = "GNU C++17"; /* Pretend C++17 until standardization. */
+ /* C++20 includes coroutines. */
+ flag_coroutines = true;
+ cxx_dialect = cxx20;
+ lang_hooks.name = "GNU C++20";
}
/* Args to -d specify what to dump. Silently ignore