diff options
author | Jakub Jelinek <jakub@redhat.com> | 2011-05-25 09:00:01 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2011-05-25 09:00:01 +0200 |
commit | 98933689804f4e8c36f5958a26b34ea7842b10a7 (patch) | |
tree | e983cd89f9335030a3aef83f37438b9d6cb1e8bc /gcc/testsuite | |
parent | 349ea8e8550b73e69673f629df24d79902b4d371 (diff) | |
download | gcc-98933689804f4e8c36f5958a26b34ea7842b10a7.zip gcc-98933689804f4e8c36f5958a26b34ea7842b10a7.tar.gz gcc-98933689804f4e8c36f5958a26b34ea7842b10a7.tar.bz2 |
re PR c++/49136 ([C++0x][constexpr] Incorrect constexpr c'tor evaluation with bitfields)
PR c++/49136
* semantics.c (cxx_eval_bit_field_ref): Handle the
case when BIT_FIELD_REF doesn't cover only a single field.
* g++.dg/cpp0x/constexpr-bitfield2.C: New test.
* g++.dg/cpp0x/constexpr-bitfield3.C: New test.
From-SVN: r174168
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield2.C | 19 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield3.C | 33 |
3 files changed, 58 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b39b4c7..af20a3e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-05-25 Jakub Jelinek <jakub@redhat.com> + + PR c++/49136 + * g++.dg/cpp0x/constexpr-bitfield2.C: New test. + * g++.dg/cpp0x/constexpr-bitfield3.C: New test. + 2011-05-24 Vladimir Makarov <vmakarov@redhat.com> PR rtl-optimization/48757 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield2.C new file mode 100644 index 0000000..531bf31 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield2.C @@ -0,0 +1,19 @@ +// PR c++/49136 +// { dg-do compile } +// { dg-options "-std=c++0x" } + +struct day +{ + unsigned d : 5; + unsigned n : 3; + constexpr explicit day (int dd) : d(dd), n(7) {} +}; + +struct date { + int d; + constexpr date (day dd) : d(dd.n != 7 ? 7 : dd.d) {} +}; + +constexpr day d(0); +constexpr date dt(d); +static_assert (dt.d == 0, "Error"); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield3.C new file mode 100644 index 0000000..b0ecbfb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-bitfield3.C @@ -0,0 +1,33 @@ +// PR c++/49136 +// { dg-do compile } +// { dg-options "-std=c++0x" } + +struct S +{ + unsigned : 1; unsigned s : 27; unsigned : 4; + constexpr S (unsigned int x) : s(x) {} +}; + +template <typename S> +struct T +{ + unsigned int t; + constexpr T (S s) : t(s.s != 7 ? 0 : s.s) {} + constexpr T (S s, S s2) : t(s.s != s2.s ? 0 : s.s) {} +}; + +constexpr S s (7), s2 (7); +constexpr T<S> t (s), t2 (s, s2); +static_assert (t.t == 7, "Error"); +static_assert (t2.t == 7, "Error"); + +struct U +{ + int a : 1; int s : 1; + constexpr U (int x, int y) : a (x), s (y) {} +}; + +constexpr U u (0, -1), u2 (-1, -1); +constexpr T<U> t3 (u), t4 (u, u2); +static_assert (t3.t == 0, "Error"); +static_assert (t4.t == -1, "Error"); |