diff options
author | Marek Polacek <polacek@redhat.com> | 2020-05-15 00:05:33 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-06-26 15:29:07 -0400 |
commit | 0801f419440c14f6772b28f763ad7d40f7f7a580 (patch) | |
tree | 2873383514dfeb12a5bfcb5eadcdca510c88aeec /gcc | |
parent | 0fce12c0920c12492c878c0ca5f639f93b93f183 (diff) | |
download | gcc-0801f419440c14f6772b28f763ad7d40f7f7a580.zip gcc-0801f419440c14f6772b28f763ad7d40f7f7a580.tar.gz gcc-0801f419440c14f6772b28f763ad7d40f7f7a580.tar.bz2 |
c++: Change the default dialect to C++17.
Since GCC 9, C++17 support is no longer experimental. It was too late
to change the default C++ dialect to C++17 in GCC 10, but I think now
it's time to pull the trigger (C++14 was made the default in GCC 6.1).
We're still missing two C++17 library features, but that shouldn't stop
us. See
<https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2017>
and
<https://gcc.gnu.org/projects/cxx-status.html#cxx17>
for the C++17 status.
I won't list all C++17 features here, but just a few heads-up:
- trigraphs were removed (hardly anyone cares, unless your keyboard is
missing the # key),
- operator++(bool) was removed (so some tests now run in C++14 and down
only),
- the keyword register was removed (some legacy code might trip on
this),
- noexcept specification is now part of the type system and C++17 does
not allow dynamic exception specifications anymore (the empty throw
specification is still available, but it is deprecated),
- the evaluation order rules are different in C++17,
- static constexpr data members are now implicitly inline (which makes
them definitions),
- C++17 requires guaranteed copy elision, meaning that a copy/move
constructor call might be elided completely. That means that if
something relied on a constructor being instantiated via e.g. copying
a function parameter, it might now fail.
I'll post an update for cxx-status.html and add a new caveat to changes.html
once this is in.
gcc/ChangeLog:
* doc/invoke.texi (C Dialect Options): Adjust -std default for C++.
* doc/standards.texi (C Language): Correct the default dialect.
(C++ Language): Update the default for C++ to gnu++17.
gcc/c-family/ChangeLog:
* c-opts.c (c_common_init_options): Default to gnu++17.
gcc/testsuite/ChangeLog:
* c-c++-common/torture/vector-subscript-3.c: In C++17, define away
the keyword register.
* g++.dg/cpp1z/attributes-enum-1a.C: Only run pre-C++17.
* g++.dg/cpp1z/fold7a.C: Likewise.
* g++.dg/cpp1z/nontype3a.C: Likewise.
* g++.dg/cpp1z/utf8-2a.C: Likewise.
* g++.dg/parse/error11.C: Update expected diagnostics for C++17.
* g++.dg/torture/pr34850.C: Add -Wno-attribute-warning.
* g++.dg/torture/pr49394.C: In C++17, use noexcept(false).
* g++.dg/torture/pr82154.C: Use -std=c++14.
* lib/target-supports.exp: Set to C++17.
* obj-c++.dg/try-catch-9.mm: Use -Wno-register.
libgomp/ChangeLog:
* testsuite/libgomp.c++/atomic-3.C: Use -std=gnu++14.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-opts.c | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 2 | ||||
-rw-r--r-- | gcc/doc/standards.texi | 4 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/torture/vector-subscript-3.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/fold7a.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/nontype3a.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/utf8-2a.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/error11.C | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr34850.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr49394.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr82154.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/lib/target-supports.exp | 2 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/try-catch-9.mm | 2 |
14 files changed, 34 insertions, 20 deletions
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 8a5131b..9b6300f 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -256,9 +256,9 @@ c_common_init_options (unsigned int decoded_options_count, } } - /* 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; } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 98cc0f2..e21d8a5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2368,7 +2368,6 @@ The name @samp{c++1y} is deprecated. @item gnu++14 @itemx gnu++1y GNU dialect of @option{-std=c++14}. -This is the default for C++ code. The name @samp{gnu++1y} is deprecated. @item c++17 @@ -2379,6 +2378,7 @@ The name @samp{c++1z} is deprecated. @item gnu++17 @itemx gnu++1z GNU dialect of @option{-std=c++17}. +This is the default for C++ code. The name @samp{gnu++1z} is deprecated. @item c++20 diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi index f39d8b3..fc50160 100644 --- a/gcc/doc/standards.texi +++ b/gcc/doc/standards.texi @@ -130,7 +130,7 @@ select an extended version of the C language explicitly with extensions). The default, if no C language dialect options are given, -is @option{-std=gnu11}. +is @option{-std=gnu17}. The ISO C standard defines (in clause 4) two classes of conforming implementation. A @dfn{conforming hosted implementation} supports the @@ -246,7 +246,7 @@ select an extended version of the C++ language explicitly with @option{-std=gnu++17} (for C++17 with GNU extensions). The default, if -no C++ language dialect options are given, is @option{-std=gnu++14}. +no C++ language dialect options are given, is @option{-std=gnu++17}. @section Objective-C and Objective-C++ Languages @cindex Objective-C diff --git a/gcc/testsuite/c-c++-common/torture/vector-subscript-3.c b/gcc/testsuite/c-c++-common/torture/vector-subscript-3.c index bb5c914..05d24f4 100644 --- a/gcc/testsuite/c-c++-common/torture/vector-subscript-3.c +++ b/gcc/testsuite/c-c++-common/torture/vector-subscript-3.c @@ -10,6 +10,9 @@ struct vec_s { vector short member; }; +#if defined(__cplusplus) && __cplusplus >= 201703L +#define register /* nothing */ +#endif int main () { register short vector v0 = {1,2,3,4,5,6,7}; diff --git a/gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C b/gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C index aacfac8..20f0b1d 100644 --- a/gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C +++ b/gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C @@ -1,4 +1,5 @@ -// This macro should not be defined without -std=c++17. +// { dg-do compile { target c++14_down } } +// This macro should not be defined without c++17. #ifdef __cpp_enumerator_attributes #error __cpp_enumerator_attributes defined diff --git a/gcc/testsuite/g++.dg/cpp1z/fold7a.C b/gcc/testsuite/g++.dg/cpp1z/fold7a.C index 5c782ff..8cca879 100644 --- a/gcc/testsuite/g++.dg/cpp1z/fold7a.C +++ b/gcc/testsuite/g++.dg/cpp1z/fold7a.C @@ -1,4 +1,5 @@ -// This macro should not be defined without -std=c++17. +// { dg-do compile { target c++14_down } } +// This macro should not be defined without c++17. #ifdef __cpp_fold_expressions #error __cpp_fold_expressions defined diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype3a.C b/gcc/testsuite/g++.dg/cpp1z/nontype3a.C index a704e50..b3ffe03 100644 --- a/gcc/testsuite/g++.dg/cpp1z/nontype3a.C +++ b/gcc/testsuite/g++.dg/cpp1z/nontype3a.C @@ -1,4 +1,5 @@ -// This macro should not be defined without -std=c++17. +// { dg-do compile { target c++14_down } } +// This macro should not be defined without c++17. #ifdef __cpp_nontype_template_args #error __cpp_nontype_template_args defined diff --git a/gcc/testsuite/g++.dg/cpp1z/utf8-2a.C b/gcc/testsuite/g++.dg/cpp1z/utf8-2a.C index 0e243d6..b2a99a9 100644 --- a/gcc/testsuite/g++.dg/cpp1z/utf8-2a.C +++ b/gcc/testsuite/g++.dg/cpp1z/utf8-2a.C @@ -1,4 +1,5 @@ -// This macro should not be 201411 without -std=c++17. +// { dg-do compile { target c++14_down } } +// This macro should not be 201411 without c++17. #if __cpp_unicode_characters == 201411 #error Wrong value for __cpp_unicode_characters diff --git a/gcc/testsuite/g++.dg/parse/error11.C b/gcc/testsuite/g++.dg/parse/error11.C index 1a49d6e..4baf97e 100644 --- a/gcc/testsuite/g++.dg/parse/error11.C +++ b/gcc/testsuite/g++.dg/parse/error11.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-fshow-column" }" +// { dg-options "-fshow-column" } // Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org> // Try to find out when the digraph '<:' is used as a mistake, and parse it // correctly to avoid cascaded errors. @@ -50,12 +50,16 @@ void func(void) // the special error message. Foo<: :B> k2; // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" } Foo[:B> k1; // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" } -// { dg-error "6:missing template arguments before" "template" { target *-*-* } 51 } -// { dg-error "9:expected primary-expression before ':' token" "primary" { target *-*-* } 51 } -// { dg-error "8:expected '\]' before ':' token" "backslash" { target *-*-* } 51 } -// { dg-error "6:missing template arguments before" "template" { target *-*-* } 52 } -// { dg-error "7:expected primary-expression before ':' token" "primary" { target *-*-* } 52 } -// { dg-error "7:expected '\]' before ':' token" "backslash" { target *-*-* } 52 } +// { dg-error "6:missing template arguments before" "template" { target c++14_down } .-2 } +// { dg-error "9:expected primary-expression before ':' token" "primary" { target c++14_down } .-3 } +// { dg-error "8:expected '\]' before ':' token" "backslash" { target c++14_down } .-4 } +// { dg-error "6:missing template arguments before" "template" { target c++14_down } .-4 } +// { dg-error "7:expected primary-expression before ':' token" "primary" { target c++14_down } .-5 } +// { dg-error "7:expected '\]' before ':' token" "backslash" { target c++14_down } .-6 } +// { dg-error "9:expected identifier" "" { target c++17 } .-8 } +// { dg-error "8:expected" "" { target c++17 } .-9 } +// { dg-error "7:expected identifier" "" { target c++17 } .-9 } +// { dg-error "7:expected" "" { target c++17 } .-10 } // int Foo[2]; Foo[::value] = 0; diff --git a/gcc/testsuite/g++.dg/torture/pr34850.C b/gcc/testsuite/g++.dg/torture/pr34850.C index c4d808c..59dd5df 100644 --- a/gcc/testsuite/g++.dg/torture/pr34850.C +++ b/gcc/testsuite/g++.dg/torture/pr34850.C @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ -/* { dg-options "-ffat-lto-objects -Wno-return-type" } */ +/* { dg-options "-ffat-lto-objects -Wno-return-type -Wno-attribute-warning" } */ typedef unsigned char uint8_t; typedef unsigned int uint32_t; diff --git a/gcc/testsuite/g++.dg/torture/pr49394.C b/gcc/testsuite/g++.dg/torture/pr49394.C index 7bd8fd4..75901a5 100644 --- a/gcc/testsuite/g++.dg/torture/pr49394.C +++ b/gcc/testsuite/g++.dg/torture/pr49394.C @@ -7,6 +7,8 @@ struct Mutex ~Mutex () #if __cplusplus <= 201402L throw(int) // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } } +#else + noexcept(false) #endif { if (locked) diff --git a/gcc/testsuite/g++.dg/torture/pr82154.C b/gcc/testsuite/g++.dg/torture/pr82154.C index e229c3e..698340d 100644 --- a/gcc/testsuite/g++.dg/torture/pr82154.C +++ b/gcc/testsuite/g++.dg/torture/pr82154.C @@ -1,5 +1,6 @@ // { dg-do compile } -// { dg-additional-options "-Wno-deprecated" } +// { dg-additional-options "-std=c++14 -Wno-deprecated" } +// C++17 does not allow dynamic exception specification. namespace a { int b; diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 2279361..4bdcaef 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -9089,7 +9089,7 @@ proc check_effective_target_c++ { } { return 0 } -set cxx_default "c++14" +set cxx_default "c++17" # Check whether the current active language standard supports the features # of C++11/C++14 by checking for the presence of one of the -std flags. # This assumes that the default for the compiler is $cxx_default, and that diff --git a/gcc/testsuite/obj-c++.dg/try-catch-9.mm b/gcc/testsuite/obj-c++.dg/try-catch-9.mm index 73c7c99..b2dc61b 100644 --- a/gcc/testsuite/obj-c++.dg/try-catch-9.mm +++ b/gcc/testsuite/obj-c++.dg/try-catch-9.mm @@ -6,7 +6,7 @@ /* { dg-xfail-run-if "PR23616" { *-*-* } { "-fgnu-runtime" } { "-fnext-runtime" } } */ /* { dg-xfail-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" "-fgnu-runtime" } { "" } } /* { dg-prune-output ".*internal compiler error.*" } */ -/* { dg-options "-fobjc-exceptions -O2" } */ +/* { dg-options "-fobjc-exceptions -O2 -Wno-register" } */ #include "../objc-obj-c++-shared/TestsuiteObject.m" #include <stdlib.h> |