Re: [PATCH v2] c++: Change the default dialect to C++17.

2020-05-22 Thread Jason Merrill via Gcc-patches

On 5/19/20 7:34 PM, Marek Polacek wrote:

On Mon, May 18, 2020 at 03:51:36PM -0400, Jason Merrill wrote:

On 5/16/20 6:34 PM, Marek Polacek wrote:

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

and

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.

Jakub, the last point is actually what I encountered in for-27.C and it
looks like an OpenMP issue, in that it wrongly depends on an implicit
instantiation.  Am I mistaken?

Due to the 'register' removal, this patch depends on the regenerated
cfns.h version I posted earlier today.

I'll post an update for cxx-status.html and add a new caveat to changes.html
once this is in.

Bootstrapped/regtested on x86_64-pc-linux-gnu, aarch64-unknown-linux-gnu,
and powerpc64le-unknown-linux-gnu.  Ok for trunk?

* 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.

* c-opts.c (c_common_init_options): Default to gnu++17.

* c-c++-common/torture/vector-subscript-3.c: Remove the register
keywords.
* g++.dg/cpp1z/attributes-enum-1a.C: Update for 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: Use c++14_down.
* g++.dg/torture/pr34850.C: Add -Wno-attribute-warning.
* g++.dg/torture/pr49394.C: Add dg-warning.
* g++.dg/torture/pr82154.C: Use -std=c++14.
* g++.dg/ubsan/pr85029.C: Use -Wno-register.
* g++.dg/ubsan/vptr-12.C: Use -fstrong-eval-order=some.
* lib/target-supports.exp: Set to C++17.
* obj-c++.dg/try-catch-9.mm: Use -Wno-register.

* testsuite/libgomp.c++/atomic-3.C: Use -std=gnu++14.
* testsuite/libgomp.c++/for-27.C: Explicitly instantiate the
copy constructor for I.
---
   gcc/c-family/c-opts.c   | 4 ++--
   gcc/doc/invoke.texi | 2 +-
   gcc/doc/standards.texi  | 4 ++--
   gcc/testsuite/c-c++-common/torture/vector-subscript-3.c | 6 +++---
   gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C | 4 ++--
   gcc/testsuite/g++.dg/cpp1z/fold7a.C | 4 ++--
   gcc/testsuite/g++.dg/cpp1z/nontype3a.C  | 4 ++--
   gcc/testsuite/g++.dg/cpp1z/utf8-2a.C| 4 ++--
   gcc/testsuite/g++.dg/parse/error11.C| 5 +++--
   gcc/testsuite/g++.dg/torture/pr34850.C  | 2 +-
   gcc/testsuite/g++.dg/torture/pr49394.C  | 2 +-
   gcc/testsuite/g++.dg/torture/pr82154.C  | 3 ++-
   gcc/testsuite/g++.dg/ubsan/pr85029.C| 2 +-
   gcc/testsuite/g++.dg/ubsan/vptr-12.C| 2 +-
   gcc/testsuite/lib/target-supports.exp   | 2 +-
   gcc/testsuite/obj-c++.dg/try-catch-9.mm | 2 +-
   libgomp/testsuite/libgomp.c++/atomic-3.C| 3 ++-
   libgomp/testsuite/libgomp.c++/for-27.C  | 6 ++
   18 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 7695e88c130..5b266c06f3b 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);
 

Re: [PATCH v2] c++: Change the default dialect to C++17.

2020-05-19 Thread Marek Polacek via Gcc-patches
On Mon, May 18, 2020 at 03:51:36PM -0400, Jason Merrill wrote:
> On 5/16/20 6:34 PM, Marek Polacek wrote:
> > 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
> > 
> > and
> > 
> > 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.
> > 
> > Jakub, the last point is actually what I encountered in for-27.C and it
> > looks like an OpenMP issue, in that it wrongly depends on an implicit
> > instantiation.  Am I mistaken?
> > 
> > Due to the 'register' removal, this patch depends on the regenerated
> > cfns.h version I posted earlier today.
> > 
> > I'll post an update for cxx-status.html and add a new caveat to changes.html
> > once this is in.
> > 
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, aarch64-unknown-linux-gnu,
> > and powerpc64le-unknown-linux-gnu.  Ok for trunk?
> > 
> > * 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.
> > 
> > * c-opts.c (c_common_init_options): Default to gnu++17.
> > 
> > * c-c++-common/torture/vector-subscript-3.c: Remove the register
> > keywords.
> > * g++.dg/cpp1z/attributes-enum-1a.C: Update for 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: Use c++14_down.
> > * g++.dg/torture/pr34850.C: Add -Wno-attribute-warning.
> > * g++.dg/torture/pr49394.C: Add dg-warning.
> > * g++.dg/torture/pr82154.C: Use -std=c++14.
> > * g++.dg/ubsan/pr85029.C: Use -Wno-register.
> > * g++.dg/ubsan/vptr-12.C: Use -fstrong-eval-order=some.
> > * lib/target-supports.exp: Set to C++17.
> > * obj-c++.dg/try-catch-9.mm: Use -Wno-register.
> > 
> > * testsuite/libgomp.c++/atomic-3.C: Use -std=gnu++14.
> > * testsuite/libgomp.c++/for-27.C: Explicitly instantiate the
> > copy constructor for I.
> > ---
> >   gcc/c-family/c-opts.c   | 4 ++--
> >   gcc/doc/invoke.texi | 2 +-
> >   gcc/doc/standards.texi  | 4 ++--
> >   gcc/testsuite/c-c++-common/torture/vector-subscript-3.c | 6 +++---
> >   gcc/testsuite/g++.dg/cpp1z/attributes-enum-1a.C | 4 ++--
> >   gcc/testsuite/g++.dg/cpp1z/fold7a.C | 4 ++--
> >   gcc/testsuite/g++.dg/cpp1z/nontype3a.C  | 4 ++--
> >   gcc/testsuite/g++.dg/cpp1z/utf8-2a.C| 4 ++--
> >   gcc/testsuite/g++.dg/parse/error11.C| 5 +++--
> >   gcc/testsuite/g++.dg/torture/pr34850.C  | 2 +-
> >   gcc/testsuite/g++.dg/torture/pr49394.C  | 2 +-
> >   gcc/testsuite/g++.dg/torture/pr82154.C  | 3 ++-
> >   gcc/testsuite/g++.dg/ubsan/pr85029.C| 2 +-
> >   gcc/testsuite/g++.dg/ubsan/vptr-12.C| 2 +-
> >   gcc/testsuite/lib/target-supports.exp   | 2 +-
> >   gcc/testsuite/obj-c++.dg/try-catch-9.mm | 2 +-
> >   libgomp/testsuite/libgomp.c++/atomic-3.C| 3 ++-
> >   libgomp/testsuite/libgomp.c++/for-27.C  | 6 ++
> >   18 files changed, 35 insertions(+), 26 deletions(-)
> > 
> > diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
> > index 7695e88c130..5b266c06f3b 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