aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-10-25 13:23:44 -0400
committerJason Merrill <jason@gcc.gnu.org>2016-10-25 13:23:44 -0400
commitf64e0c029c452c9fc508adebf18d0ceb3ffdc066 (patch)
treeaadf065579df3086e8a1c0647f565aec732d4588 /gcc
parent90e261e494a5f1fda83b815f513c5621fa5f8c83 (diff)
downloadgcc-f64e0c029c452c9fc508adebf18d0ceb3ffdc066.zip
gcc-f64e0c029c452c9fc508adebf18d0ceb3ffdc066.tar.gz
gcc-f64e0c029c452c9fc508adebf18d0ceb3ffdc066.tar.bz2
constexpr.c (maybe_constant_init): Pull out TARGET_EXPR_INITIAL.
* constexpr.c (maybe_constant_init): Pull out TARGET_EXPR_INITIAL. (cxx_eval_outermost_constant_expr): Don't return a CONSTRUCTOR with CONSTRUCTOR_NO_IMPLICIT_ZERO. (cxx_eval_call_expression): Clear CONSTRUCTOR_NO_IMPLICIT_ZERO. From-SVN: r241531
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/constexpr.c16
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-static12.C20
3 files changed, 43 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9c876b8..1276d13 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2016-10-25 Jason Merrill <jason@redhat.com>
+
+ * constexpr.c (maybe_constant_init): Pull out TARGET_EXPR_INITIAL.
+ (cxx_eval_outermost_constant_expr): Don't return a CONSTRUCTOR
+ with CONSTRUCTOR_NO_IMPLICIT_ZERO.
+ (cxx_eval_call_expression): Clear CONSTRUCTOR_NO_IMPLICIT_ZERO.
+
2016-10-25 Jakub Jelinek <jakub@redhat.com>
* parser.c (cp_parser_postfix_expression): Adding missing break;.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 8f7b7f3..1ebd647 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1665,6 +1665,10 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
entry->result = result;
}
+ /* The result of a constexpr function must be completely initialized. */
+ if (TREE_CODE (result) == CONSTRUCTOR)
+ CONSTRUCTOR_NO_IMPLICIT_ZERO (result) = false;
+
pop_cx_call_context ();
return unshare_constructor (result);
}
@@ -4483,6 +4487,16 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
non_constant_p = true;
}
+ if (TREE_CODE (r) == CONSTRUCTOR
+ && CONSTRUCTOR_NO_IMPLICIT_ZERO (r))
+ {
+ if (!allow_non_constant)
+ error ("%qE is not a constant expression because it refers to "
+ "an incompletely initialized variable", t);
+ TREE_CONSTANT (r) = false;
+ non_constant_p = true;
+ }
+
/* Technically we should check this for all subexpressions, but that
runs into problems with our internal representation of pointer
subtraction and the 5.19 rules are still in flux. */
@@ -4781,6 +4795,8 @@ maybe_constant_init (tree t, tree decl)
t = TREE_OPERAND (t, 0);
if (TREE_CODE (t) == INIT_EXPR)
t = TREE_OPERAND (t, 1);
+ if (TREE_CODE (t) == TARGET_EXPR)
+ t = TARGET_EXPR_INITIAL (t);
if (!potential_nondependent_static_init_expression (t))
/* Don't try to evaluate it. */;
else
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-static12.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-static12.C
new file mode 100644
index 0000000..4faa8cf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-static12.C
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++11 } }
+// { dg-final { scan-assembler-not "_ZNSt10unique_ptrC1Ei" } }
+
+namespace std {
+ struct unique_ptr {
+ constexpr unique_ptr(int) : p() { }
+ ~unique_ptr() { }
+ void* p;
+ };
+}
+
+void f()
+{
+ static std::unique_ptr p(1);
+}
+
+int main()
+{
+ f();
+}