From: Jason Merrill Date: Wed, 19 Nov 2014 03:03:45 +0000 (-0500) Subject: re PR c++/63924 (Constexpr constructible expression "is not constexpr" when used... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=052beba43fcefe280c617045f03dfe37fcd5b81a;p=gcc.git re PR c++/63924 (Constexpr constructible expression "is not constexpr" when used in a template non-type argument) PR c++/63924 * constexpr.c (cxx_eval_constant_expression) [PARM_DECL]: A load from a variable of empty class type is constant. From-SVN: r217749 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 32f2c6f3300..5769d2af30e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2014-11-18 Jason Merrill + PR c++/63924 + * constexpr.c (cxx_eval_constant_expression) [PARM_DECL]: A load + from a variable of empty class type is constant. + * constexpr.c (cxx_eval_statement_list): Handle statement-expressions. (potential_constant_expression_1): Handle STMT_EXPR. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 1b330a048df..1303fdc4d08 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2845,6 +2845,12 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = *p; else if (addr) /* Defer in case this is only used for its type. */; + else if (is_empty_class (TREE_TYPE (t))) + { + /* If the class is empty, we aren't actually loading anything. */ + r = build_constructor (TREE_TYPE (t), NULL); + TREE_CONSTANT (r) = true; + } else { if (!ctx->quiet) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-empty8.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty8.C new file mode 100644 index 00000000000..8c1414af558 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty8.C @@ -0,0 +1,7 @@ +// PR c++/63924 +// { dg-do compile { target c++11 } } + +struct A { }; +constexpr bool f(A a) { return true; } +template constexpr bool g() { return true; } +constexpr bool g(A a) { return g(); }