aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-11-13 19:06:48 -0500
committerJason Merrill <jason@gcc.gnu.org>2010-11-13 19:06:48 -0500
commit2e5748d2868d1c8d24d84fe0bcf9916cf0ffc527 (patch)
tree84b63e06c1023a70ed249614db5aad83a0de1ba7
parentd86216483294d8789d2f92168511d6508c80dbd1 (diff)
downloadgcc-2e5748d2868d1c8d24d84fe0bcf9916cf0ffc527.zip
gcc-2e5748d2868d1c8d24d84fe0bcf9916cf0ffc527.tar.gz
gcc-2e5748d2868d1c8d24d84fe0bcf9916cf0ffc527.tar.bz2
decl.c (cp_finish_decl): Use resolve_nondeduced_context for auto.
* decl.c (cp_finish_decl): Use resolve_nondeduced_context for auto. * init.c (build_new): Likewise. * pt.c (tsubst_decl): Likewise. (do_auto_deduction): Likewise. (resolve_nondeduced_context): Use build_offset_ref and cp_build_addr_expr. From-SVN: r166724
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/decl.c1
-rw-r--r--gcc/cp/init.c9
-rw-r--r--gcc/cp/pt.c21
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/auto20.C20
6 files changed, 56 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 192f35a..418951a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2010-11-13 Jason Merrill <jason@redhat.com>
+
+ * decl.c (cp_finish_decl): Use resolve_nondeduced_context for auto.
+ * init.c (build_new): Likewise.
+ * pt.c (tsubst_decl): Likewise.
+ (do_auto_deduction): Likewise.
+ (resolve_nondeduced_context): Use build_offset_ref and
+ cp_build_addr_expr.
+
2010-11-12 Joseph Myers <joseph@codesourcery.com>
* Make-lang.in (g++spec.o): Use $(OPTS_H).
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7891c1e..714516e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5761,6 +5761,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
if (TREE_CODE (d_init) == TREE_LIST)
d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
tf_warning_or_error);
+ d_init = resolve_nondeduced_context (d_init);
if (describable_type (d_init))
{
type = TREE_TYPE (decl) = do_auto_deduction (type, d_init,
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 00b5d9b..670c7a5 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2516,8 +2516,13 @@ build_new (VEC(tree,gc) **placement, tree type, tree nelts,
if (nelts == NULL_TREE && VEC_length (tree, *init) == 1)
{
tree auto_node = type_uses_auto (type);
- if (auto_node && describable_type (VEC_index (tree, *init, 0)))
- type = do_auto_deduction (type, VEC_index (tree, *init, 0), auto_node);
+ if (auto_node)
+ {
+ tree d_init = VEC_index (tree, *init, 0);
+ d_init = resolve_nondeduced_context (d_init);
+ if (describable_type (d_init))
+ type = do_auto_deduction (type, d_init, auto_node);
+ }
}
if (processing_template_decl)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 56b7543..3e8b62c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10035,10 +10035,14 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
= tsubst_expr (DECL_INITIAL (t), args, complain, in_decl,
/*constant_expression_p=*/false);
- if (auto_node && init && describable_type (init))
+ if (auto_node && init)
{
- type = do_auto_deduction (type, init, auto_node);
- TREE_TYPE (r) = type;
+ init = resolve_nondeduced_context (init);
+ if (describable_type (init))
+ {
+ type = do_auto_deduction (type, init, auto_node);
+ TREE_TYPE (r) = type;
+ }
}
}
else
@@ -14338,10 +14342,13 @@ resolve_nondeduced_context (tree orig_expr)
BASELINK_ACCESS_BINFO (baselink),
expr, BASELINK_OPTYPE (baselink));
if (offset)
- expr = build2 (OFFSET_REF, TREE_TYPE (expr),
- TREE_OPERAND (offset, 0), expr);
+ {
+ tree base
+ = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (offset, 0)));
+ expr = build_offset_ref (base, expr, addr);
+ }
if (addr)
- expr = build_address (expr);
+ expr = cp_build_addr_expr (expr, tf_warning_or_error);
return expr;
}
else if (good == 0 && badargs)
@@ -18890,6 +18897,8 @@ do_auto_deduction (tree type, tree init, tree auto_node)
if (BRACE_ENCLOSED_INITIALIZER_P (init))
type = listify_autos (type, auto_node);
+ init = resolve_nondeduced_context (init);
+
parms = build_tree_list (NULL_TREE, type);
args[0] = init;
tparms = make_tree_vec (1);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 70dcd0d..f5456a1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-13 Jason Merrill <jason@redhat.com>
+
+ * g++.dg/cpp0x/auto20.C: New.
+
2010-11-13 Iain Sandoe <iains@gcc.gnu.org>
* objc.dg/fsf-nsstring-format-1.m: Adjust format messages.
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto20.C b/gcc/testsuite/g++.dg/cpp0x/auto20.C
new file mode 100644
index 0000000..90f8751
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto20.C
@@ -0,0 +1,20 @@
+// Test for proper non-deduced context handling of the initializer
+// for an auto declaration/new.
+// { dg-options -std=c++0x }
+
+struct with_apply
+{
+ template <unsigned>
+ void apply(const double&){}
+};
+
+auto p = &with_apply::apply<0>;
+auto pp = new auto(&with_apply::apply<0>);
+
+template <class T>
+void f()
+{
+ auto p = &T::template apply<0>;
+}
+
+template void f<with_apply>();