gcc/libgomp/testsuite/libgomp.c++/atomic-3.C
Marek Polacek 0801f41944 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.
2020-06-26 15:29:07 -04:00

77 lines
1.1 KiB
C

// { dg-do run }
// C++17 forbids ++ on bool.
// { dg-options "-Wno-deprecated -std=gnu++14" }
extern "C" void abort (void);
bool v, x1, x2, x3, x4, x5, x6;
void
foo ()
{
#pragma omp atomic capture
v = ++x1;
if (!v)
abort ();
#pragma omp atomic capture
v = x2++;
if (v)
abort ();
#pragma omp atomic read
v = x3;
if (!v)
abort ();
#pragma omp atomic read
v = x4;
if (!v)
abort ();
#pragma omp atomic capture
{ v = x5; x5 |= 1; }
if (v)
abort ();
#pragma omp atomic capture
{ x6 |= 1; v = x6; }
if (!v)
abort ();
}
void
bar ()
{
#pragma omp atomic write
x1 = false;
#pragma omp atomic write
x2 = false;
#pragma omp atomic capture
{ ++x1; v = x1; }
if (!v)
abort ();
#pragma omp atomic capture
{ v = x2; x2++; }
if (v)
abort ();
#pragma omp atomic write
x1 = false;
#pragma omp atomic write
x2 = false;
#pragma omp atomic capture
{ x1++; v = x1; }
if (!v)
abort ();
#pragma omp atomic capture
{ v = x2; ++x2; }
if (v)
abort ();
}
int
main ()
{
#pragma omp atomic write
x3 = true;
#pragma omp atomic write
x4 = true;
foo ();
bar ();
return 0;
}