Hi!

On Wed, 6 Jul 2016 16:20:44 -0600, Martin Sebor <mse...@gmail.com> wrote:
> PR c++/60760 - arithmetic on null pointers should not be allowed in constant
>   expressions
> PR c++/71091 - constexpr reference bound to a null pointer dereference
>    accepted
> 
> [...]
>       * g++.dg/cpp0x/constexpr-cast.C: New test.

In x86_64 GNU/Linux testing, I see that one FAIL for the -m32 multilib:

    +FAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++11  (test for errors, line 10)
    +FAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++11  (test for errors, line 11)
    +PASS: g++.dg/cpp0x/constexpr-cast.C  -std=c++11  (test for errors, line 24)
    +FAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++11 (test for excess errors)
    +XFAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++11 bug c++/49171 (test for 
errors, line 8)
    +FAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++14  (test for errors, line 10)
    +FAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++14  (test for errors, line 11)
    +PASS: g++.dg/cpp0x/constexpr-cast.C  -std=c++14  (test for errors, line 24)
    +FAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++14 (test for excess errors)
    +XFAIL: g++.dg/cpp0x/constexpr-cast.C  -std=c++14 bug c++/49171 (test for 
errors, line 8)
    +UNSUPPORTED: g++.dg/cpp0x/constexpr-cast.C  -std=c++98

    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:10:22: error: 
'reinterpret_cast<void*>(1)' is not a constant-expression
    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:11:22: error: 
'reinterpret_cast<void*>(1u)' is not a constant-expression
    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:24:26:   in 
constexpr expansion of 'f<int>()'
    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:24:27: error: 
value '4u' of type 'int*' is not a constant expression

For the -m64 multilib, it looks as follows (all PASSes):

    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:10:47: error: 
value '1u' of type 'void*' is not a constant expression
    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:11:22: error: 
'reinterpret_cast<void*>(1ul)' is not a constant-expression
    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:24:26:   in 
constexpr expansion of 'f<int>()'
    [...]/source-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C:24:27: error: 
value '4u' of type 'int*' is not a constant expression

For reference:

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C
> @@ -0,0 +1,24 @@
> +// Test to verify that evaluating reinterpret_cast is diagnosed in
> +// constant expressions.
> +// { dg-do compile { target c++11 } }
> +
> +int i;
> +
> +// The following is accepted due to bug 49171.
> +constexpr void *q = reinterpret_cast<void*>(&i);    // { dg-error "" "bug 
> c++/49171" { xfail *-*-*-* } }
> +
> +constexpr void *r0 = reinterpret_cast<void*>(1);    // { dg-error "not a 
> constant expression" }
> +constexpr void *r1 = reinterpret_cast<void*>(sizeof 'x');  // { dg-error 
> ".reinterpret_cast<void\\*>\\(1ul\\). is not a constant-expression" }
> +
> +template <class T>
> +constexpr bool f ()
> +{
> +#if __cplusplus > 201103L
> +  T *p = reinterpret_cast<T*>(sizeof (T));
> +  return p;
> +#else
> +  return *reinterpret_cast<T*>(sizeof (T));
> +#endif
> +}
> +
> +constexpr bool b = f<int>();   // { dg-error "not a constant expression" }


Grüße
 Thomas

Attachment: signature.asc
Description: PGP signature

Reply via email to