+2018-10-17 Joseph Myers <joseph@codesourcery.com>
+
+ * doc/cpp.texi (__STDC_VERSION__): Document C2X handling.
+ * doc/invoke.texi (-std=c2x, -std=gnu2x): Document new options.
+ * doc/standards.texi (C Language): Document C2X.
+ * dwarf2out.c (highest_c_language), config/rl78/rl78.c
+ (rl78_option_override): Handle "GNU C2X" language name.
+
2018-10-17 Joseph Myers <joseph@codesourcery.com>
* doc/invoke.texi (-std=c17), doc/standards.texi (C Language):
+2018-10-17 Joseph Myers <joseph@codesourcery.com>
+
+ * c-common.c (flag_isoc2x): New variable.
+ * c-common.h (clk_c): Update comment to reference C2X.
+ (flag_isoc99, flag_isoc11): Update comments to reference future
+ standard versions in general.
+ (flag_isoc2x): Declare.
+ * c-opts.c (set_std_c2x): New function.
+ (c_common_handle_option): Handle -std=c2x and -std=gnu2x.
+ (set_std_c89, set_std_c99, set_std_c11, set_std_c17): Set
+ flag_isoc2x to 0.
+ * c.opt (Wc11-c2x-compat, std=c2x, std=gnu2x): New options.
+
2018-10-17 Joseph Myers <joseph@codesourcery.com>
* c.opt (std=c17, std=c18, std=gnu17, std=gnu18, std=iso9899:2017)
int flag_isoc11;
+/* Nonzero means use the ISO C2X dialect of C. */
+
+int flag_isoc2x;
+
/* Nonzero means that we have builtin functions, and main is an int. */
int flag_hosted = 1;
enum c_language_kind
{
- clk_c = 0, /* C90, C94, C99 or C11 */
+ clk_c = 0, /* C90, C94, C99, C11 or C2X */
clk_objc = 1, /* clk_c with ObjC features. */
clk_cxx = 2, /* ANSI/ISO C++ */
clk_objcxx = 3 /* clk_cxx with ObjC features. */
extern int flag_isoc94;
-/* Nonzero means use the ISO C99 (or C11) dialect of C. */
+/* Nonzero means use the ISO C99 (or later) dialect of C. */
extern int flag_isoc99;
-/* Nonzero means use the ISO C11 dialect of C. */
+/* Nonzero means use the ISO C11 (or later) dialect of C. */
extern int flag_isoc11;
+/* Nonzero means use the ISO C2X dialect of C. */
+
+extern int flag_isoc2x;
+
/* Nonzero means that we have builtin functions, and main is an int. */
extern int flag_hosted;
static void set_std_c99 (int);
static void set_std_c11 (int);
static void set_std_c17 (int);
+static void set_std_c2x (int);
static void check_deps_environment_vars (void);
static void handle_deferred_opts (void);
static void sanitize_cpp_opts (void);
set_std_c17 (false /* ISO */);
break;
+ case OPT_std_c2x:
+ if (!preprocessing_asm_p)
+ set_std_c2x (true /* ISO */);
+ break;
+
+ case OPT_std_gnu2x:
+ if (!preprocessing_asm_p)
+ set_std_c2x (false /* ISO */);
+ break;
+
case OPT_trigraphs:
cpp_opts->trigraphs = 1;
break;
flag_isoc94 = c94;
flag_isoc99 = 0;
flag_isoc11 = 0;
+ flag_isoc2x = 0;
lang_hooks.name = "GNU C89";
}
flag_no_asm = iso;
flag_no_nonansi_builtin = iso;
flag_iso = iso;
+ flag_isoc2x = 0;
flag_isoc11 = 0;
flag_isoc99 = 1;
flag_isoc94 = 1;
flag_no_asm = iso;
flag_no_nonansi_builtin = iso;
flag_iso = iso;
+ flag_isoc2x = 0;
flag_isoc11 = 1;
flag_isoc99 = 1;
flag_isoc94 = 1;
flag_no_asm = iso;
flag_no_nonansi_builtin = iso;
flag_iso = iso;
+ flag_isoc2x = 0;
flag_isoc11 = 1;
flag_isoc99 = 1;
flag_isoc94 = 1;
lang_hooks.name = "GNU C17";
}
+/* Set the C 2X standard (without GNU extensions if ISO). */
+static void
+set_std_c2x (int iso)
+{
+ cpp_set_lang (parse_in, iso ? CLK_STDC2X: CLK_GNUC2X);
+ flag_no_asm = iso;
+ flag_no_nonansi_builtin = iso;
+ flag_iso = iso;
+ flag_isoc2x = 1;
+ flag_isoc11 = 1;
+ flag_isoc99 = 1;
+ flag_isoc94 = 1;
+ lang_hooks.name = "GNU C2X";
+}
+
/* Set the C++ 98 standard (without GNU extensions if ISO). */
static void
C ObjC C++ ObjC++ CPP(warn_builtin_macro_redefined) CppReason(CPP_W_BUILTIN_MACRO_REDEFINED) Var(cpp_warn_builtin_macro_redefined) Init(1) Warning
Warn when a built-in preprocessor macro is undefined or redefined.
+Wc11-c2x-compat
+C ObjC Var(warn_c11_c2x_compat) Init(-1) Warning
+Warn about features not present in ISO C11, but present in ISO C2X.
+
Wc90-c99-compat
C ObjC CPP(cpp_warn_c90_c99_compat) CppReason(CPP_W_C90_C99_COMPAT) Var(warn_c90_c99_compat) Init(-1) Warning
Warn about features not present in ISO C90, but present in ISO C99.
C ObjC Alias(std=c17)
Conform to the ISO 2017 C standard (published in 2018).
+std=c2x
+C ObjC
+Conform to the ISO 202X C standard draft (experimental and incomplete support).
+
std=c89
C ObjC Alias(std=c90)
Conform to the ISO 1990 C standard.
C ObjC Alias(std=gnu17)
Conform to the ISO 2017 C standard (published in 2018) with GNU extensions.
+std=gnu2x
+C ObjC
+Conform to the ISO 202X C standard draft with GNU extensions (experimental and incomplete support).
+
std=gnu89
C ObjC Alias(std=gnu90)
Conform to the ISO 1990 C standard with GNU extensions.
+2018-10-17 Joseph Myers <joseph@codesourcery.com>
+
+ * c-errors.c (pedwarn_c11): New function.
+ * c-parser.c (disable_extension_diagnostics): Save
+ warn_c11_c2x_compat and set it to 0.
+ (restore_extension_diagnostics): Restore warn_c11_c2x_compat.
+ (c_parser_static_assert_declaration_no_semi): Handle
+ _Static_assert without string constant.
+ * c-tree.h (pedwarn_c11): New prototype.
+
2018-10-17 David Malcolm <dmalcolm@redhat.com>
* Make-lang.in (selftest-c): New.
#include "c-tree.h"
#include "opts.h"
+/* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C2X mode,
+ otherwise issue warning MSGID if -Wc11-c2X-compat is specified.
+ This function is supposed to be used for matters that are allowed in
+ ISO C2X but not supported in ISO C11, thus we explicitly don't pedwarn
+ when C2X is specified. */
+
+bool
+pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...)
+{
+ diagnostic_info diagnostic;
+ va_list ap;
+ bool warned = false;
+ rich_location richloc (line_table, location);
+
+ va_start (ap, gmsgid);
+ /* If desired, issue the C11/C2X compat warning, which is more specific
+ than -pedantic. */
+ if (warn_c11_c2x_compat > 0)
+ {
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
+ (pedantic && !flag_isoc2x)
+ ? DK_PEDWARN : DK_WARNING);
+ diagnostic.option_index = OPT_Wc11_c2x_compat;
+ warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
+ }
+ /* -Wno-c11-c2x-compat suppresses even the pedwarns. */
+ else if (warn_c11_c2x_compat == 0)
+ ;
+ /* For -pedantic outside C2X, issue a pedwarn. */
+ else if (pedantic && !flag_isoc2x)
+ {
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
+ diagnostic.option_index = opt;
+ warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
+ }
+ va_end (ap);
+ return warned;
+}
+
/* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
otherwise issue warning MSGID if -Wc99-c11-compat is specified.
This function is supposed to be used for matters that are allowed in
/* Similarly for warn_c99_c11_compat. */
| ((warn_c99_c11_compat == 1) << 9)
| ((warn_c99_c11_compat == -1) << 10)
+ /* Similarly for warn_c11_c2x_compat. */
+ | ((warn_c11_c2x_compat == 1) << 11)
+ | ((warn_c11_c2x_compat == -1) << 12)
);
cpp_opts->cpp_pedantic = pedantic = 0;
warn_pointer_arith = 0;
warn_overlength_strings = 0;
warn_c90_c99_compat = 0;
warn_c99_c11_compat = 0;
+ warn_c11_c2x_compat = 0;
return ret;
}
/* See above for why is this needed. */
warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0);
+ warn_c11_c2x_compat = (flags >> 11) & 1 ? 1 : ((flags >> 12) & 1 ? -1 : 0);
}
/* Helper data structure for parsing #pragma acc routine. */
static_assert-declaration-no-semi:
_Static_assert ( constant-expression , string-literal )
+
+ C2X:
+ static_assert-declaration-no-semi:
+ _Static_assert ( constant-expression )
*/
static void
{
location_t assert_loc, value_loc;
tree value;
- tree string;
+ tree string = NULL_TREE;
gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
assert_loc = c_parser_peek_token (parser)->location;
value = c_parser_expr_no_commas (parser, NULL).value;
value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
parser->lex_untranslated_string = true;
- if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
- {
- parser->lex_untranslated_string = false;
- return;
- }
- switch (c_parser_peek_token (parser)->type)
+ if (c_parser_next_token_is (parser, CPP_COMMA))
{
- case CPP_STRING:
- case CPP_STRING16:
- case CPP_STRING32:
- case CPP_WSTRING:
- case CPP_UTF8STRING:
- string = c_parser_peek_token (parser)->value;
c_parser_consume_token (parser);
- parser->lex_untranslated_string = false;
- break;
- default:
- c_parser_error (parser, "expected string literal");
- parser->lex_untranslated_string = false;
- return;
+ switch (c_parser_peek_token (parser)->type)
+ {
+ case CPP_STRING:
+ case CPP_STRING16:
+ case CPP_STRING32:
+ case CPP_WSTRING:
+ case CPP_UTF8STRING:
+ string = c_parser_peek_token (parser)->value;
+ c_parser_consume_token (parser);
+ parser->lex_untranslated_string = false;
+ break;
+ default:
+ c_parser_error (parser, "expected string literal");
+ parser->lex_untranslated_string = false;
+ return;
+ }
}
+ else if (flag_isoc11)
+ /* If pedantic for pre-C11, the use of _Static_assert itself will
+ have been diagnosed, so do not also diagnose the use of this
+ new C2X feature of _Static_assert. */
+ pedwarn_c11 (assert_loc, OPT_Wpedantic,
+ "ISO C11 does not support omitting the string in "
+ "%<_Static_assert%>");
parens.require_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
}
constant_expression_warning (value);
if (integer_zerop (value))
- error_at (assert_loc, "static assertion failed: %E", string);
+ {
+ if (string)
+ error_at (assert_loc, "static assertion failed: %E", string);
+ else
+ error_at (assert_loc, "static assertion failed");
+ }
}
/* Parse some declaration specifiers (possibly none) (C90 6.5, C99
ATTRIBUTE_GCC_DIAG(3,4);
extern bool pedwarn_c99 (location_t, int opt, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
+extern bool pedwarn_c11 (location_t, int opt, const char *, ...)
+ ATTRIBUTE_GCC_DIAG(3,4);
extern void
set_c_expr_source_range (c_expr *expr,
&& strcmp (lang_hooks.name, "GNU C")
&& strcmp (lang_hooks.name, "GNU C11")
&& strcmp (lang_hooks.name, "GNU C17")
+ && strcmp (lang_hooks.name, "GNU C2X")
&& strcmp (lang_hooks.name, "GNU C89")
&& strcmp (lang_hooks.name, "GNU C99")
/* Compiling with -flto results in a language of GNU GIMPLE being used... */
signifies the 2011 revision of the C standard; the value
@code{201710L} signifies the 2017 revision of the C standard (which is
otherwise identical to the 2011 version apart from correction of
-defects).
+defects). An unspecified value larger than @code{201710L} is used for
+the experimental @option{-std=c2x} and @option{-std=gnu2x} modes.
This macro is not defined if the @option{-traditional-cpp} option is
used, nor when compiling C++ or Objective-C@.
applied with @option{-std=c11}) and a new value of
@code{__STDC_VERSION__}, and so is supported to the same extent as C11.
+@item c2x
+The next version of the ISO C standard, still under development. The
+support for this version is experimental and incomplete.
+
@item gnu90
@itemx gnu89
GNU dialect of ISO C90 (including some C99 features).
@itemx gnu18
GNU dialect of ISO C17. This is the default for C code.
+@item gnu2x
+The next version of the ISO C standard, still under development, plus
+GNU extensions. The support for this version is experimental and
+incomplete.
+
@item c++98
@itemx c++03
The 1998 ISO C++ standard plus the 2003 technical corrigendum and some
@cindex C1X
@cindex ISO C17
@cindex C17
+@cindex ISO C2X
+@cindex C2X
@cindex Technical Corrigenda
@cindex TC1
@cindex Technical Corrigendum 1
@option{-std=c11}, and the only difference between the options is the
value of @code{__STDC_VERSION__}.
+A further version of the C standard, known as @dfn{C2X}, is under
+development; experimental and incomplete support for this is enabled
+with @option{-std=c2x}.
+
By default, GCC provides some extensions to the C language that, on
rare occasions conflict with the C standard. @xref{C
Extensions,,Extensions to the C Language Family}.
if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
return "GNU C++98";
+ if (strcmp ("GNU C2X", lang1) == 0 || strcmp ("GNU C2X", lang2) == 0)
+ return "GNU C2X";
if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) == 0)
return "GNU C17";
if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
if (dwarf_version >= 5 /* || !dwarf_strict */)
if (strcmp (language_string, "GNU C11") == 0
- || strcmp (language_string, "GNU C17") == 0)
+ || strcmp (language_string, "GNU C17") == 0
+ || strcmp (language_string, "GNU C2X"))
language = DW_LANG_C11;
}
}
+2018-10-17 Joseph Myers <joseph@codesourcery.com>
+
+ * gcc.dg/c11-static-assert-7.c, gcc.dg/c11-static-assert-8.c,
+ gcc.dg/c11-static-assert-9.c, gcc.dg/c2x-static-assert-1.c,
+ gcc.dg/c2x-static-assert-2.c, gcc.dg/c99-static-assert-2.c,
+ gcc.dg/gnu2x-static-assert-1.c: New tests.
+ * gcc.dg/missing-symbol-3.c: Update expected fix-it text.
+
2018-10-17 Tobias Burnus <burnus@net-b.de>
PR fortran/87632
--- /dev/null
+/* Test C11 static assertions. Omitting the string not supported. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic" } */
+
+_Static_assert (1); /* { dg-warning "does not support omitting the string" } */
--- /dev/null
+/* Test C11 static assertions. Omitting the string not supported. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+_Static_assert (1); /* { dg-error "does not support omitting the string" } */
--- /dev/null
+/* Test C11 static assertions. Omitting the string not supported, but
+ -Wno-c11-c2x-compat disables the -pedantic diagnostic for that. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic -Wno-c11-c2x-compat" } */
+
+_Static_assert (1);
--- /dev/null
+/* Test C2x static assertions. Omitting the string supported. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic" } */
+
+_Static_assert (1);
--- /dev/null
+/* Test C2x static assertions. Omitting the string supported. Failed
+ assertions. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic" } */
+
+_Static_assert (0); /* { dg-error "static assertion failed" } */
--- /dev/null
+/* Test static assertions. Omitting the string should not result in a
+ duplicate diagnostic in pre-C11 modes. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic" } */
+
+_Static_assert (1); /* { dg-warning "ISO C99 does not support '_Static_assert'" } */
--- /dev/null
+/* Test C11 static assertions. Omitting the string diagnosed with
+ -Wc11-c2x-compat. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu2x -Wc11-c2x-compat" } */
+
+_Static_assert (1); /* { dg-warning "does not support omitting the string" } */
void test_static_assert_2 (void)
{
- _Static_assert(sizeof(int) >= sizeof(char); /* { dg-error "expected ',' before ';' token" } */
+ _Static_assert(sizeof(int) >= sizeof(char); /* { dg-error "expected '\\)' before ';' token" } */
/* { dg-begin-multiline-output "" }
_Static_assert(sizeof(int) >= sizeof(char);
- ^
- ,
+ ~ ^
+ )
{ dg-end-multiline-output "" } */
}
+2018-10-17 Joseph Myers <joseph@codesourcery.com>
+
+ * include/cpplib.h (enum c_lang): Add CLK_GNUC2X and CLK_STDC2X.
+ * init.c (lang_defaults): Add GNUC2X and STDC2X entries.
+ (cpp_init_builtins): Define __STDC_VERSION__ to 202000L for C2X.
+
2018-10-11 David Malcolm <dmalcolm@redhat.com>
* macro.c (_cpp_arguments_ok): If the argument count is wrong, add
#undef TK
/* C language kind, used when calling cpp_create_reader. */
-enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17,
+enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_STDC17,
+ CLK_STDC2X,
CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};
/* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
+ /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
/* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
/* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
/* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
/* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
+ /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
/* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
/* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
/* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
_cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
else if (CPP_OPTION (pfile, lang) == CLK_STDC94)
_cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
+ else if (CPP_OPTION (pfile, lang) == CLK_STDC2X
+ || CPP_OPTION (pfile, lang) == CLK_GNUC2X)
+ _cpp_define_builtin (pfile, "__STDC_VERSION__ 202000L");
else if (CPP_OPTION (pfile, lang) == CLK_STDC17
|| CPP_OPTION (pfile, lang) == CLK_GNUC17)
_cpp_define_builtin (pfile, "__STDC_VERSION__ 201710L");