From aee69156daee2e9ca8e9f80ecd1c5b8c808946f5 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Mon, 31 Oct 2016 18:52:23 +0200 Subject: [PATCH] Add tests for a const member and a reference member for launder. * g++.dg/cpp1z/launder3.C: New. * g++.dg/cpp1z/launder4.C: Likewise. * g++.dg/cpp1z/launder5.C: Likewise. * g++.dg/cpp1z/launder5.cc: Likewise. * g++.dg/cpp1z/launder5.h: Likewise. * g++.dg/cpp1z/launder6.C: Likewise. * g++.dg/cpp1z/launder6.cc: Likewise. * g++.dg/cpp1z/launder6.h: Likewise. From-SVN: r241708 --- gcc/testsuite/ChangeLog | 12 ++++++++ gcc/testsuite/g++.dg/cpp1z/launder3.C | 38 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/launder4.C | 40 ++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/launder5.C | 25 ++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/launder5.cc | 12 ++++++++ gcc/testsuite/g++.dg/cpp1z/launder5.h | 16 +++++++++++ gcc/testsuite/g++.dg/cpp1z/launder6.C | 24 ++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/launder6.cc | 14 +++++++++ gcc/testsuite/g++.dg/cpp1z/launder6.h | 16 +++++++++++ 9 files changed, 197 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder3.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder4.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder5.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder5.cc create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder5.h create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder6.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder6.cc create mode 100644 gcc/testsuite/g++.dg/cpp1z/launder6.h diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c298d498eb8..58d5ce2b80e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2016-10-31 Ville Voutilainen + + Add tests for a const member and a reference member for launder. + * g++.dg/cpp1z/launder3.C: New. + * g++.dg/cpp1z/launder4.C: Likewise. + * g++.dg/cpp1z/launder5.C: Likewise. + * g++.dg/cpp1z/launder5.cc: Likewise. + * g++.dg/cpp1z/launder5.h: Likewise. + * g++.dg/cpp1z/launder6.C: Likewise. + * g++.dg/cpp1z/launder6.cc: Likewise. + * g++.dg/cpp1z/launder6.h: Likewise. + 2016-10-31 Jakub Jelinek PR c++/77948 diff --git a/gcc/testsuite/g++.dg/cpp1z/launder3.C b/gcc/testsuite/g++.dg/cpp1z/launder3.C new file mode 100644 index 00000000000..2a2afc5cad1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder3.C @@ -0,0 +1,38 @@ +// { dg-do run { target c++11 } } +// { dg-additional-options "-O2" } + +#include + +void * +operator new (decltype (sizeof (0)), void *p) +{ + return p; +} + +namespace std +{ + template + T * + launder (T *p) + { + return __builtin_launder (p); + } +} + +struct A +{ + const int x; +}; + +struct B +{ + A a; +}; + +int +main () +{ + B b{{42}}; + new (&b.a) A{666}; + assert(std::launder(&b.a)->x == 666); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/launder4.C b/gcc/testsuite/g++.dg/cpp1z/launder4.C new file mode 100644 index 00000000000..3a65eb27f2e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder4.C @@ -0,0 +1,40 @@ +// { dg-do run { target c++11 } } +// { dg-additional-options "-O2" } + +#include + +void * +operator new (decltype (sizeof (0)), void *p) +{ + return p; +} + +namespace std +{ + template + T * + launder (T *p) + { + return __builtin_launder (p); + } +} + +struct A +{ + int& x; +}; + +struct B +{ + A a; +}; + +int +main () +{ + int x = 42; + B b{{x}}; + int y = 666; + new (&b.a) A{y}; + assert(std::launder(&b.a)->x == 666); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/launder5.C b/gcc/testsuite/g++.dg/cpp1z/launder5.C new file mode 100644 index 00000000000..483d6f29297 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder5.C @@ -0,0 +1,25 @@ +// { dg-do run { target c++11 } } +// { dg-additional-options "-O2" } +// { dg-additional-sources "launder5.cc" } + +#include +#include "launder5.h" + +namespace std +{ + template + T * + launder (T *p) + { + return __builtin_launder (p); + } +} + + +int +main () +{ + B b{{42}}; + f(b); + assert(std::launder(&b.a)->x == 666); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/launder5.cc b/gcc/testsuite/g++.dg/cpp1z/launder5.cc new file mode 100644 index 00000000000..f9d867db332 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder5.cc @@ -0,0 +1,12 @@ +#include "launder5.h" + +void * +operator new (decltype (sizeof (0)), void *p) +{ + return p; +} + +void f(B& b) +{ + new (&b.a) A{666}; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/launder5.h b/gcc/testsuite/g++.dg/cpp1z/launder5.h new file mode 100644 index 00000000000..b66103aefba --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder5.h @@ -0,0 +1,16 @@ +#ifndef GCC_TEST_LAUNDER5_H +#define GCC_TEST_LAUNDER5_H + +struct A +{ + const int x; +}; + +struct B +{ + A a; +}; + +void f(B& b); + +#endif diff --git a/gcc/testsuite/g++.dg/cpp1z/launder6.C b/gcc/testsuite/g++.dg/cpp1z/launder6.C new file mode 100644 index 00000000000..babc4b433ad --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder6.C @@ -0,0 +1,24 @@ +// { dg-do run { target c++11 } } +// { dg-additional-options "-O2" } +// { dg-additional-sources "launder6.cc" } +#include +#include "launder6.h" + +namespace std +{ + template + T * + launder (T *p) + { + return __builtin_launder (p); + } +} + +int +main () +{ + int x = 42; + B b{{x}}; + f(b); + assert(std::launder(&b.a)->x == 666); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/launder6.cc b/gcc/testsuite/g++.dg/cpp1z/launder6.cc new file mode 100644 index 00000000000..1822891a0a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder6.cc @@ -0,0 +1,14 @@ +#include "launder6.h" + +void * +operator new (decltype (sizeof (0)), void *p) +{ + return p; +} + +int y = 666; + +void f(B& b) +{ + new (&b.a) A{y}; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/launder6.h b/gcc/testsuite/g++.dg/cpp1z/launder6.h new file mode 100644 index 00000000000..eca2ad46f18 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/launder6.h @@ -0,0 +1,16 @@ +#ifndef GCC_TEST_LAUNDER6_H +#define GCC_TEST_LAUNDER6_H + +struct A +{ + int& x; +}; + +struct B +{ + A a; +}; + +void f(B& b); + +#endif -- 2.30.2