public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Allow void type as a literal type in C++14
@ 2014-11-21 18:25 Marek Polacek
  2014-11-28 15:49 ` Marek Polacek
  2014-12-01 14:37 ` Jason Merrill
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Polacek @ 2014-11-21 18:25 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

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  <polacek@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ PATCH] Allow void type as a literal type in C++14
  2014-11-21 18:25 [C++ PATCH] Allow void type as a literal type in C++14 Marek Polacek
@ 2014-11-28 15:49 ` Marek Polacek
  2014-12-01 14:37 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2014-11-28 15:49 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

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  <polacek@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ PATCH] Allow void type as a literal type in C++14
  2014-11-21 18:25 [C++ PATCH] Allow void type as a literal type in C++14 Marek Polacek
  2014-11-28 15:49 ` Marek Polacek
@ 2014-12-01 14:37 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2014-12-01 14:37 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

OK.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-01 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-21 18:25 [C++ PATCH] Allow void type as a literal type in C++14 Marek Polacek
2014-11-28 15:49 ` Marek Polacek
2014-12-01 14:37 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).