From 596334fa040094c772965ff1998d171fe3e00348 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 15 Jan 2020 14:45:24 -0500 Subject: PR c++/93257 - consteval void function. A prvalue can have void type, and if it doesn't do anything prohibited in a constant expression, it's vacuously constant. * constexpr.c (verify_constant): Allow void_node. --- gcc/cp/ChangeLog | 3 +++ gcc/cp/constexpr.c | 3 ++- gcc/testsuite/g++.dg/cpp2a/consteval-void1.C | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval-void1.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 78eb834..95eb2a7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2020-01-15 Jason Merrill + PR c++/93257 - consteval void function. + * constexpr.c (verify_constant): Allow void_node. + PR c++/92871 - bad code with xvalue and GNU ?: extension. * call.c (prevent_lifetime_extension): New. (build_conditional_expr_1): Use it. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index bb126a9..17b04d7 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 0000000..783cf4c --- /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 +consteval void test() {} + +int main() { + test(); + return 0; +} -- cgit v1.1