From ccafc19b5bd8f4736a2788263aa5acd6d2b7a961 Mon Sep 17 00:00:00 2001 From: Jason Merrill <jason@redhat.com> Date: Tue, 2 Jun 2009 13:02:27 -0400 Subject: [PATCH] re PR c++/40306 (ICE when using auto to declare a local copy inside a member function) PR c++/40306 PR c++/40307 * decl.c (cp_finish_decl): Handle auto deduction from (). * typeck.c (build_x_indirect_ref): Handle dereferencing an operand with dependent type that is known to be a pointer. From-SVN: r148088 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 4 +++- gcc/cp/typeck.c | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/auto14.C | 29 +++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 33fbcef4cab7..448b55815638 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2009-06-01 Jason Merrill <jason@redhat.com> + + PR c++/40306 + PR c++/40307 + * decl.c (cp_finish_decl): Handle auto deduction from (). + * typeck.c (build_x_indirect_ref): Handle dereferencing an operand + with dependent type that is known to be a pointer. + 2009-06-02 Simon Martin <simartin@users.sourceforge.net> PR c++/38089 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a626a71fc342..645ac7e41b55 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5531,7 +5531,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, TREE_TYPE (decl) = error_mark_node; return; } - else if (describable_type (init)) + if (TREE_CODE (init) == TREE_LIST) + init = build_x_compound_expr_from_list (init, "initializer"); + if (describable_type (init)) { type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node); if (type == error_mark_node) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index eb28a3d268e7..6f6bd3923b00 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2449,6 +2449,10 @@ build_x_indirect_ref (tree expr, const char *errorstring, if (processing_template_decl) { + /* Retain the type if we know the operand is a pointer so that + describable_type doesn't make auto deduction break. */ + if (TREE_TYPE (expr) && POINTER_TYPE_P (TREE_TYPE (expr))) + return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr); if (type_dependent_expression_p (expr)) return build_min_nt (INDIRECT_REF, expr); expr = build_non_dependent_expr (expr); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6865ff2d52b1..9743b5dafec2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-06-02 Jason Merrill <jason@redhat.com> + + * g++.dg/cpp0x/auto14.C: New. + 2009-06-02 Eric Botcazou <ebotcazou@adacore.com> * gnat.dg/alignment6.adb: Remove XFAIL. diff --git a/gcc/testsuite/g++.dg/cpp0x/auto14.C b/gcc/testsuite/g++.dg/cpp0x/auto14.C new file mode 100644 index 000000000000..cb2c4e0351a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto14.C @@ -0,0 +1,29 @@ +// PR c++/40306, c++/40307 +// { dg-options "-std=c++0x" } +// { dg-do run } + +template< typename T > +struct test { + test run() { + auto tmp = *this; + return tmp; + } + test run_pass() { + test tmp( *this ); + return tmp; + } + + test run_fail() { + auto tmp( *this ); + return tmp; + } +}; + +int main() +{ + test<int> x; + x.run(); + x.run_pass(); + x.run_fail(); + return 0; +} -- GitLab