* C++ PATCH for c++/50473 (constexpr and static reference members)
@ 2014-11-17 20:37 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2014-11-17 20:37 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 227 bytes --]
Trying to establish a constant value for an uninstantiated constexpr
reference is complicated because of temporary binding semantics. Best
to just treat it as value-dependent.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 50473.patch --]
[-- Type: text/x-patch, Size: 2877 bytes --]
commit 23fbd2ea665ffbc88722f918d8acc44c70614fc0
Author: Jason Merrill <jason@redhat.com>
Date: Sun Nov 16 23:35:27 2014 -0500
PR c++/50473
* decl.c (cp_finish_decl): Don't try to process a non-dependent
constant initializer for a reference.
* pt.c (value_dependent_expression_p): A reference is always
dependent.
* call.c (extend_ref_init_temps_1): Also clear TREE_SIDE_EFFECTS
on any NOP_EXPRs.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4f0b172..06162aa 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9712,9 +9712,11 @@ extend_ref_init_temps_1 (tree decl, tree init, vec<tree, va_gc> **cleanups)
{
tree subinit = NULL_TREE;
*p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit);
+ recompute_tree_invariant_for_addr_expr (sub);
+ if (init != sub)
+ init = fold_convert (TREE_TYPE (init), sub);
if (subinit)
init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
- recompute_tree_invariant_for_addr_expr (sub);
}
return init;
}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 47da0ca..e69b521 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6419,6 +6419,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
else if (init
&& init_const_expr_p
&& !type_dependent_p
+ && TREE_CODE (type) != REFERENCE_TYPE
&& decl_maybe_constant_var_p (decl)
&& !type_dependent_init_p (init)
&& !value_dependent_init_p (init))
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1ee3dc1..c0f3b8c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20959,6 +20959,8 @@ value_dependent_expression_p (tree expression)
if (DECL_INITIAL (expression)
&& decl_constant_var_p (expression)
&& (TREE_CODE (DECL_INITIAL (expression)) == TREE_LIST
+ /* cp_finish_decl doesn't fold reference initializers. */
+ || TREE_CODE (TREE_TYPE (expression)) == REFERENCE_TYPE
|| value_dependent_expression_p (DECL_INITIAL (expression))))
return true;
return false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice12.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice12.C
index 98f53b1..c548337 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice12.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice12.C
@@ -3,7 +3,7 @@
struct A
{
- static constexpr int&& i = 0; // { dg-error "initialization" }
+ static constexpr int&& i = 0;
};
int j = A::i;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ref5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref5.C
new file mode 100644
index 0000000..230510c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref5.C
@@ -0,0 +1,13 @@
+// PR c++/50473
+// { dg-do compile { target c++11 } }
+
+constexpr int f() { return 1; }
+
+template<class T>
+struct test
+{
+ static constexpr const auto& value = f();
+ int a[value];
+};
+
+test<int> t;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-11-17 20:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-17 20:37 C++ PATCH for c++/50473 (constexpr and static reference members) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).