diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index e79a571..c1daaa2 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2017-07-18 Andrew Sutton + + Add support for -std=c++2a. + * c-common.h (cxx_dialect): Add cxx2a as a dialect. + * opt.c: Add options for -std=c++2a and -std=gnu++2a. + * c-opts.c (set_std_cxx2a): New. + (c_common_handle_option): Set options when -std=c++2a is enabled. + 2017-07-18 Nathan Sidwell * c-warn.c (warn_for_memset): Use TYPE_{MIN,MAX}_VALUE. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index a29f1ad..c6a855f 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -713,7 +713,9 @@ enum cxx_dialect { /* C++14 */ cxx14, /* C++1z (C++17?) */ - cxx1z + cxx1z, + /* C++2a (C++20?) */ + cxx2a }; /* The C++ dialect being used. C++98 is the default. */ diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 1657e7a..eed9e72 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -111,6 +111,7 @@ static void set_std_cxx98 (int); static void set_std_cxx11 (int); static void set_std_cxx14 (int); static void set_std_cxx1z (int); +static void set_std_cxx2a (int); static void set_std_c89 (int, int); static void set_std_c99 (int); static void set_std_c11 (int); @@ -637,6 +638,12 @@ c_common_handle_option (size_t scode, const char *arg, int value, set_std_cxx1z (code == OPT_std_c__1z /* ISO */); break; + case OPT_std_c__2a: + case OPT_std_gnu__2a: + if (!preprocessing_asm_p) + set_std_cxx2a (code == OPT_std_c__2a /* ISO */); + break; + case OPT_std_c90: case OPT_std_iso9899_199409: if (!preprocessing_asm_p) @@ -1604,7 +1611,23 @@ set_std_cxx1z (int iso) flag_isoc99 = 1; flag_isoc11 = 1; cxx_dialect = cxx1z; - lang_hooks.name = "GNU C++14"; /* Pretend C++14 till standarization. */ + lang_hooks.name = "GNU C++14"; /* Pretend C++14 till standardization. */ +} + +/* Set the C++ 202a draft standard (without GNU extensions if ISO). */ +static void +set_std_cxx2a (int iso) +{ + cpp_set_lang (parse_in, iso ? CLK_CXX2A: CLK_GNUCXX2A); + flag_no_gnu_keywords = iso; + flag_no_nonansi_builtin = iso; + flag_iso = iso; + /* C++1z includes the C99 standard library. */ + flag_isoc94 = 1; + flag_isoc99 = 1; + flag_isoc11 = 1; + cxx_dialect = cxx2a; + lang_hooks.name = "GNU C++17"; /* Pretend C++17 until standardization. */ } /* Args to -d specify what to dump. Silently ignore diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index e0ad3ab..15a969a 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1923,6 +1923,10 @@ Conform to the ISO 2017(?) C++ draft standard (experimental and incomplete suppo std=c++17 C++ ObjC++ Alias(std=c++1z) Undocumented +std=c++2a +C++ ObjC++ +Conform to the ISO 2020(?) C++ draft standard (experimental and incomplete support). + std=c11 C ObjC Conform to the ISO 2011 C standard. @@ -1980,6 +1984,10 @@ Conform to the ISO 201z(7?) C++ draft standard with GNU extensions (experimental std=gnu++17 C++ ObjC++ Alias(std=gnu++1z) Undocumented +std=gnu++2a +C++ ObjC++ +Conform to the ISO 2020(?) C++ draft standard with GNU extensions (experimental and incomplete support). + std=gnu11 C ObjC Conform to the ISO 2011 C standard with GNU extensions. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cad1ade..ab8e997 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-07-19 Andrew Sutton + + New test for -std=c++2a. + * g++.dg/cpp2a/cplusplus.C: New. + 2017-07-19 Jakub Jelinek PR tree-optimization/81346 diff --git a/gcc/testsuite/g++.dg/cpp2a/cplusplus.C b/gcc/testsuite/g++.dg/cpp2a/cplusplus.C new file mode 100644 index 0000000..614fc52 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/cplusplus.C @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-std=c++2a" } + +static_assert(__cplusplus > 201703L); diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index cf6f924..887f0cb 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2017-07-07 Andrew Sutton + + Add support for C++2a. + * include/cpplib.h (c_lang): Add CXX2A and GNUCXX2A. + * init.c (lang_defaults): Add rows for CXX2A and GNUCXX2A. + (cpp_init_builtins): Set __cplusplus to 202007L for C++2x. + 2017-07-07 David Malcolm PR c++/79300 diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 66ef4d6..bd93c3b 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -171,7 +171,8 @@ enum cpp_ttype enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, - CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX1Z, CLK_CXX1Z, CLK_ASM}; + CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX1Z, CLK_CXX1Z, + CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM}; /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ struct GTY(()) cpp_string { diff --git a/libcpp/init.c b/libcpp/init.c index 1477673..5b68550 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -110,6 +110,8 @@ static const struct lang_flags lang_defaults[] = /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, /* GNUCXX1Z */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 }, /* CXX1Z */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 }, + /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 }, + /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 }, /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; @@ -497,7 +499,10 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) if (CPP_OPTION (pfile, cplusplus)) { - if (CPP_OPTION (pfile, lang) == CLK_CXX1Z + if (CPP_OPTION (pfile, lang) == CLK_CXX2A + || CPP_OPTION (pfile, lang) == CLK_GNUCXX2A) + _cpp_define_builtin (pfile, "__cplusplus 201707L"); + else if (CPP_OPTION (pfile, lang) == CLK_CXX1Z || CPP_OPTION (pfile, lang) == CLK_GNUCXX1Z) _cpp_define_builtin (pfile, "__cplusplus 201703L"); else if (CPP_OPTION (pfile, lang) == CLK_CXX14