aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-11-18 22:03:45 -0500
committerJason Merrill <jason@gcc.gnu.org>2014-11-18 22:03:45 -0500
commit052beba43fcefe280c617045f03dfe37fcd5b81a (patch)
tree791d225ae5241592bde9beb4dcfe27f18935728d /gcc
parent58611fb6fa0c1bab4ea0f77df43df67e9a9d19b0 (diff)
downloadgcc-052beba43fcefe280c617045f03dfe37fcd5b81a.zip
gcc-052beba43fcefe280c617045f03dfe37fcd5b81a.tar.gz
gcc-052beba43fcefe280c617045f03dfe37fcd5b81a.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/constexpr.c6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-empty8.C7
3 files changed, 17 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 32f2c6f..5769d2a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2014-11-18 Jason Merrill <jason@redhat.com>
+ 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 1b330a0..1303fdc 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 0000000..8c1414a
--- /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 <bool B> constexpr bool g() { return true; }
+constexpr bool g(A a) { return g<f(a)>(); }