Ping.

On Fri, Nov 21, 2014 at 06:55:51PM +0100, Marek Polacek wrote:
> I noticed that C++14 [basic.types] says that "a type is a literal type
> if it is: void, [...]".  Yet our literal_type_p doesn't consider void
> type as a literal type.  The following is an attempt to fix that along
> with a testcase.  It seems that void was only added in C++14, so check
> for cxx14 as well.
> 
> Bootstrapped/regtested on ppc64-linux, ok for trunk?
> 
> 2014-11-21  Marek Polacek  <pola...@redhat.com>
> 
>       * constexpr.c (literal_type_p): Return true for void type in C++14.
> 
>       * g++.dg/cpp0x/constexpr-function2.C: Limit dg-error to C++11.
>       * g++.dg/cpp0x/constexpr-neg1.C: Likewise.
>       * g++.dg/cpp1y/constexpr-void1.C: New test.
> 
> diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
> index 2678223..0a258cf 100644
> --- gcc/cp/constexpr.c
> +++ gcc/cp/constexpr.c
> @@ -59,7 +59,8 @@ literal_type_p (tree t)
>  {
>    if (SCALAR_TYPE_P (t)
>        || TREE_CODE (t) == VECTOR_TYPE
> -      || TREE_CODE (t) == REFERENCE_TYPE)
> +      || TREE_CODE (t) == REFERENCE_TYPE
> +      || (VOID_TYPE_P (t) && cxx_dialect >= cxx14))
>      return true;
>    if (CLASS_TYPE_P (t))
>      {
> diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C 
> gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C
> index 8c51c9d..95ee244 100644
> --- gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C
> +++ gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C
> @@ -23,7 +23,7 @@ constexpr int area = squarei(side); // { dg-error 
> "side|argument" }
>  int next(constexpr int x) // { dg-error "parameter" }
>  { return x + 1; }
>  
> -constexpr void f(int x)       // { dg-error "return type .void" }
> +constexpr void f(int x)       // { dg-error "return type .void" "" { target 
> c++11_only } }
>  { /* ... */ }
>  
>  constexpr int prev(int x)
> diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C 
> gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C
> index 35f5e8e..dfa1d6b 100644
> --- gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C
> +++ gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C
> @@ -29,7 +29,7 @@ int next(constexpr int x) { // { dg-error "parameter" }
>  extern constexpr int memsz;  // { dg-error "definition" }
>  
>  // error: return type is void
> -constexpr void f(int x)              // { dg-error "void" }
> +constexpr void f(int x)              // { dg-error "void" "" { target 
> c++11_only } }
>  { /* ... */ }
>  // error: use of decrement
>  constexpr int prev(int x)
> diff --git gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C 
> gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C
> index e69de29..10ef5bc 100644
> --- gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C
> +++ gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C
> @@ -0,0 +1,13 @@
> +// { dg-do compile { target c++14 } }
> +
> +struct S
> +{
> +  int i = 20;
> +
> +  constexpr void
> +  foo (void)
> +  {
> +    if (i > 20)
> +      __builtin_abort ();
> +  }
> +};
> 
>       Marek

        Marek

Reply via email to