From: Joseph Myers Date: Wed, 17 Oct 2018 23:58:54 +0000 (+0100) Subject: Add -std=c2x, -std=gnu2x, -Wc11-c2x-compat, C2X _Static_assert support. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f936c861383dc69e0053e34315d5d0262a19e8f;p=gcc.git Add -std=c2x, -std=gnu2x, -Wc11-c2x-compat, C2X _Static_assert support. Now new features are starting to be added to a C2X draft (in the C2x branch of the C standard git repository, no public WG14 document yet), it's time to add -std=c2x and associated options to GCC for use in enabling C2X features. This patch adds the expected set of options: -std=c2x, -std=gnu2x, -Wc11-c2x-compat. A first C2X feature is added (the only one so far in the repository that's obviously relevant to GCC): support (as in C++) for the string constant to be omitted in _Static_assert. This feature is duly also supported as an extension in earlier standard modes (diagnosed with -pedantic, unless -Wno-c11-c2x-compat is given, or with -Wc11-c2x-compat even in C2X mode). Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/ * 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. gcc/c/ * 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. gcc/c-family/ * 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. gcc/testsuite/ * 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. libcpp/ * 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. From-SVN: r265251 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 85bfe7f07b0..f4e147c26ee 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2018-10-17 Joseph Myers + + * 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 * doc/invoke.texi (-std=c17), doc/standards.texi (C Language): diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 2e01482832f..5b334f37360 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,16 @@ +2018-10-17 Joseph Myers + + * 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 * c.opt (std=c17, std=c18, std=gnu17, std=gnu18, std=iso9899:2017) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 2e64a6b71ac..f10cf89c3a7 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -214,6 +214,10 @@ int flag_isoc99; 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; diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 70b152f459e..641fe57d671 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -498,7 +498,7 @@ extern GTY(()) tree c_global_trees[CTI_MAX]; 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. */ @@ -635,14 +635,18 @@ extern int flag_cond_mismatch; 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; diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 10cb53b2513..9cf1900fb9a 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -117,6 +117,7 @@ static void set_std_c89 (int, int); 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); @@ -679,6 +680,16 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, 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; @@ -1554,6 +1565,7 @@ set_std_c89 (int c94, int iso) flag_isoc94 = c94; flag_isoc99 = 0; flag_isoc11 = 0; + flag_isoc2x = 0; lang_hooks.name = "GNU C89"; } @@ -1565,6 +1577,7 @@ set_std_c99 (int iso) flag_no_asm = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; + flag_isoc2x = 0; flag_isoc11 = 0; flag_isoc99 = 1; flag_isoc94 = 1; @@ -1579,6 +1592,7 @@ set_std_c11 (int iso) flag_no_asm = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; + flag_isoc2x = 0; flag_isoc11 = 1; flag_isoc99 = 1; flag_isoc94 = 1; @@ -1593,12 +1607,28 @@ set_std_c17 (int iso) 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 diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index a7c8dd5d8f3..6f88a1013d6 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -366,6 +366,10 @@ Wbuiltin-macro-redefined 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. @@ -1998,6 +2002,10 @@ std=c18 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. @@ -2068,6 +2076,10 @@ std=gnu18 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. diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 4807a322527..2c07f2f6125 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,13 @@ +2018-10-17 Joseph Myers + + * 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 * Make-lang.in (selftest-c): New. diff --git a/gcc/c/c-errors.c b/gcc/c/c-errors.c index 2d507107f0c..4ff2080e94a 100644 --- a/gcc/c/c-errors.c +++ b/gcc/c/c-errors.c @@ -25,6 +25,45 @@ along with GCC; see the file COPYING3. If not see #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 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 1f173fc10e2..ee66ce89b5d 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1327,6 +1327,9 @@ disable_extension_diagnostics (void) /* 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; @@ -1337,6 +1340,7 @@ disable_extension_diagnostics (void) warn_overlength_strings = 0; warn_c90_c99_compat = 0; warn_c99_c11_compat = 0; + warn_c11_c2x_compat = 0; return ret; } @@ -1356,6 +1360,7 @@ restore_extension_diagnostics (int flags) /* 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. */ @@ -2404,6 +2409,10 @@ c_parser_static_assert_declaration (c_parser *parser) static_assert-declaration-no-semi: _Static_assert ( constant-expression , string-literal ) + + C2X: + static_assert-declaration-no-semi: + _Static_assert ( constant-expression ) */ static void @@ -2411,7 +2420,7 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) { 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; @@ -2429,27 +2438,33 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) 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))) @@ -2473,7 +2488,12 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser) } 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 diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 017c01c592c..be63feec7bd 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -762,6 +762,8 @@ extern bool pedwarn_c90 (location_t, int opt, const char *, ...) 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, diff --git a/gcc/config/rl78/rl78.c b/gcc/config/rl78/rl78.c index 03c78fc7549..6663e355834 100644 --- a/gcc/config/rl78/rl78.c +++ b/gcc/config/rl78/rl78.c @@ -366,6 +366,7 @@ rl78_option_override (void) && 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... */ diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index 53455741fd9..cb5d5bd7775 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -1887,7 +1887,8 @@ the 1999 revision of the C standard; the value @code{201112L} 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@. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 7b080767692..bf8bcfb2907 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1933,6 +1933,10 @@ same as C11 except for corrections of defects (all of which are also 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). @@ -1950,6 +1954,11 @@ The name @samp{gnu1x} is deprecated. @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 diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi index bd9ff6bf822..26350cc9265 100644 --- a/gcc/doc/standards.texi +++ b/gcc/doc/standards.texi @@ -38,6 +38,8 @@ with some exceptions, and possibly with some extensions. @cindex C1X @cindex ISO C17 @cindex C17 +@cindex ISO C2X +@cindex C2X @cindex Technical Corrigenda @cindex TC1 @cindex Technical Corrigendum 1 @@ -109,6 +111,10 @@ known as @dfn{C17} and is supported with @option{-std=c17} or @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}. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 0772b364919..42eab9e0f66 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -24329,6 +24329,8 @@ highest_c_language (const char *lang1, const char *lang2) 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) @@ -24408,7 +24410,8 @@ gen_compile_unit_die (const char *filename) 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; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9cb109ef034..f6dbcf731c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-10-17 Joseph Myers + + * 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 PR fortran/87632 diff --git a/gcc/testsuite/gcc.dg/c11-static-assert-7.c b/gcc/testsuite/gcc.dg/c11-static-assert-7.c new file mode 100644 index 00000000000..8cea923b67b --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-static-assert-7.c @@ -0,0 +1,5 @@ +/* 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" } */ diff --git a/gcc/testsuite/gcc.dg/c11-static-assert-8.c b/gcc/testsuite/gcc.dg/c11-static-assert-8.c new file mode 100644 index 00000000000..20e5a6d1076 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-static-assert-8.c @@ -0,0 +1,5 @@ +/* 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" } */ diff --git a/gcc/testsuite/gcc.dg/c11-static-assert-9.c b/gcc/testsuite/gcc.dg/c11-static-assert-9.c new file mode 100644 index 00000000000..93696ab1b23 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-static-assert-9.c @@ -0,0 +1,6 @@ +/* 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); diff --git a/gcc/testsuite/gcc.dg/c2x-static-assert-1.c b/gcc/testsuite/gcc.dg/c2x-static-assert-1.c new file mode 100644 index 00000000000..1b771a1c0cc --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-static-assert-1.c @@ -0,0 +1,5 @@ +/* Test C2x static assertions. Omitting the string supported. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic" } */ + +_Static_assert (1); diff --git a/gcc/testsuite/gcc.dg/c2x-static-assert-2.c b/gcc/testsuite/gcc.dg/c2x-static-assert-2.c new file mode 100644 index 00000000000..c3474676e02 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-static-assert-2.c @@ -0,0 +1,6 @@ +/* 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" } */ diff --git a/gcc/testsuite/gcc.dg/c99-static-assert-2.c b/gcc/testsuite/gcc.dg/c99-static-assert-2.c new file mode 100644 index 00000000000..dffa77c64f1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-static-assert-2.c @@ -0,0 +1,6 @@ +/* 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'" } */ diff --git a/gcc/testsuite/gcc.dg/gnu2x-static-assert-1.c b/gcc/testsuite/gcc.dg/gnu2x-static-assert-1.c new file mode 100644 index 00000000000..4ed095cb3cd --- /dev/null +++ b/gcc/testsuite/gcc.dg/gnu2x-static-assert-1.c @@ -0,0 +1,6 @@ +/* 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" } */ diff --git a/gcc/testsuite/gcc.dg/missing-symbol-3.c b/gcc/testsuite/gcc.dg/missing-symbol-3.c index e2d00dfa03f..5c7aaed6a27 100644 --- a/gcc/testsuite/gcc.dg/missing-symbol-3.c +++ b/gcc/testsuite/gcc.dg/missing-symbol-3.c @@ -15,11 +15,11 @@ void test_static_assert_1 (void) 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 "" } */ } diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index e240b2c7058..fd08a330cca 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,9 @@ +2018-10-17 Joseph Myers + + * 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 * macro.c (_cpp_arguments_ok): If the argument count is wrong, add diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 797cfb92e78..a9b4fb3973c 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -167,8 +167,9 @@ enum cpp_ttype #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}; diff --git a/libcpp/init.c b/libcpp/init.c index 32a59565174..9b7490b0d8a 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -100,11 +100,13 @@ static const struct lang_flags lang_defaults[] = /* 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 }, @@ -521,6 +523,9 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) _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");