From: Jason Merrill Date: Mon, 12 Jan 2015 14:15:07 +0000 (-0500) Subject: re PR c++/64547 (A non-const constexpr function is rejected incorrectly) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=49c8bc0c77ee47f604c1e1ebe41cd9170fd33f48;p=gcc.git re PR c++/64547 (A non-const constexpr function is rejected incorrectly) PR c++/64547 * constexpr.c (cxx_eval_call_expression): A call to a void function doesn't need to return a value. From-SVN: r219466 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f60141d7beb..14e1fb323c2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-01-12 Jason Merrill + + PR c++/64547 + * constexpr.c (cxx_eval_call_expression): A call to a void + function doesn't need to return a value. + 2015-01-09 Michael Collison * call.c: Include hash-set.h, machmode.h, vec.h, double-int.h, diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 9a0d518450f..650250b015a 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1386,6 +1386,8 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, value by evaluating *this, but we don't bother; there's no need to put such a call in the hash table. */ result = lval ? ctx->object : ctx->ctor; + else if (VOID_TYPE_P (TREE_TYPE (res))) + result = void_node; else { result = *ctx->values->get (slot ? slot : res); diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-void2.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-void2.C new file mode 100644 index 00000000000..321a35ed29b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-void2.C @@ -0,0 +1,21 @@ +// PR c++/64547 +// { dg-do compile { target c++14 } } + +struct X +{ + int x; + constexpr int get() const {return x;} + constexpr void set(int foo) {x = foo;} +}; + +constexpr int bar() +{ + X x{42}; + x.set(666); + return x.get(); +} + +int main() +{ + constexpr int foo = bar(); +}