* C++ PATCH for c++/55753 (ICE with constexpr)
@ 2013-01-03 20:36 Jason Merrill
2013-01-07 16:58 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2013-01-03 20:36 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 215 bytes --]
This is a bit I missed in my 55419 patch; if we aren't setting
TREE_CONSTANT on TARGET_EXPRs in the constexpr code, we can't expect it
in the template code.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
[-- Attachment #2: 55753.patch --]
[-- Type: text/x-patch, Size: 1232 bytes --]
commit db160eb9b07b62f3696e7358c74e6d59c68385d8
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jan 3 14:43:05 2013 -0500
PR c++/55419
PR c++/55753
* pt.c (tsubst_copy_and_build) [TARGET_EXPR]: Don't touch
TREE_CONSTANT.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1b3f039..09a0aa5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14333,11 +14333,9 @@ tsubst_copy_and_build (tree t,
case TARGET_EXPR:
/* We can get here for a constant initializer of non-dependent type.
FIXME stop folding in cp_parser_initializer_clause. */
- gcc_assert (TREE_CONSTANT (t));
{
tree r = get_target_expr_sfinae (RECUR (TARGET_EXPR_INITIAL (t)),
complain);
- TREE_CONSTANT (r) = true;
RETURN (r);
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C
new file mode 100644
index 0000000..a5a4b4d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C
@@ -0,0 +1,14 @@
+// PR c++/55753
+// { dg-options -std=c++11 }
+
+template <typename Tp>
+struct C {
+ constexpr C(const Tp& r) { }
+};
+
+template <typename Tp>
+struct B {
+ B() {
+ C<double> cpl = C<double>((true ? 1.0 : C<double>()));
+ }
+};
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for c++/55753 (ICE with constexpr)
2013-01-03 20:36 C++ PATCH for c++/55753 (ICE with constexpr) Jason Merrill
@ 2013-01-07 16:58 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2013-01-07 16:58 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 523 bytes --]
And another bug: we were building an AGGR_INIT_EXPR in non-dependent
code, and then failing to handle it properly in fold_non_dependent_expr.
Fixed by not creating AGGR_INIT_EXPR in templates. As a result, we
end up with a CALL_EXPR to the address of a constructor, and we need to
avoid an error when instantiating that by stripping the address and
letting the call code put it back.
Tested x86_64-pc-linux-gnu, applying to trunk. This is only an ICE with
checking enabled, so I'm not going to apply it to 4.7.
[-- Attachment #2: 55753-2.patch --]
[-- Type: text/x-patch, Size: 1758 bytes --]
commit 843d522093cdc00181ea4590bf69d5f10162998a
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jan 7 09:31:13 2013 -0500
PR c++/55753
* tree.c (build_aggr_init_expr): Do nothing in a template.
* pt.c (tsubst_copy_and_build) [CALL_EXPR]: Strip an ADDR_EXPR off
a FUNCTION_DECL before tsubsting.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 30bafa0..c55dabef 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13743,6 +13743,11 @@ tsubst_copy_and_build (tree t,
else
qualified_p = false;
+ if (TREE_CODE (function) == ADDR_EXPR
+ && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
+ /* Avoid error about taking the address of a constructor. */
+ function = TREE_OPERAND (function, 0);
+
function = tsubst_copy_and_build (function, args, complain,
in_decl,
!qualified_p,
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index fcab1a4..0824214 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -412,6 +412,10 @@ build_aggr_init_expr (tree type, tree init)
tree rval;
int is_ctor;
+ /* Don't build AGGR_INIT_EXPR in a template. */
+ if (processing_template_decl)
+ return init;
+
if (TREE_CODE (init) == CALL_EXPR)
fn = CALL_EXPR_FN (init);
else if (TREE_CODE (init) == AGGR_INIT_EXPR)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor13.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor13.C
new file mode 100644
index 0000000..ed01a31
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor13.C
@@ -0,0 +1,15 @@
+// PR c++/55753
+// { dg-options -std=c++11 }
+
+struct A
+{
+ double r,i;
+ constexpr A(double r = 0.0, double i = 0.0): r(r), i(i) {}
+};
+
+template <typename Tp>
+struct B {
+ B() {
+ A((true ? 1.0 : A()));
+ }
+};
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-01-07 16:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-03 20:36 C++ PATCH for c++/55753 (ICE with constexpr) Jason Merrill
2013-01-07 16:58 ` 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).