public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] PR c++/93257 - consteval void function.
@ 2020-01-15 20:30 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2020-01-15 20:30 UTC (permalink / raw)
  To: gcc-patches

A prvalue can have void type, and if it doesn't do anything prohibited in a
constant expression, it's vacuously constant.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* constexpr.c (verify_constant): Allow void_node.
---
 gcc/cp/constexpr.c                           |  3 ++-
 gcc/testsuite/g++.dg/cpp2a/consteval-void1.C | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval-void1.C

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index bb126a9c006..17b04d7b055 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2609,7 +2609,8 @@ static bool
 verify_constant (tree t, bool allow_non_constant, bool *non_constant_p,
 		 bool *overflow_p)
 {
-  if (!*non_constant_p && !reduced_constant_expression_p (t))
+  if (!*non_constant_p && !reduced_constant_expression_p (t)
+      && t != void_node)
     {
       if (!allow_non_constant)
 	error ("%q+E is not a constant expression", t);
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-void1.C b/gcc/testsuite/g++.dg/cpp2a/consteval-void1.C
new file mode 100644
index 00000000000..783cf4c7ef7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval-void1.C
@@ -0,0 +1,10 @@
+// PR c++/93257
+// { dg-do compile { target c++2a } }
+
+template <bool, typename>
+consteval void test() {}
+
+int main() {
+    test<false, int>();
+    return 0;
+}

base-commit: 7192b1ec12484f5ca8b20930d8dc4d28ab4a533a
-- 
2.18.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-15 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 20:30 [C++ PATCH] PR c++/93257 - consteval void function 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).