diff options
author | Jason Merrill <jason@redhat.com> | 2011-03-16 13:04:30 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-03-16 13:04:30 -0400 |
commit | bb4586d38825faf532f8dd12c73049410563ee7c (patch) | |
tree | b52452674927ebc84d6820aa58bd3129547bd535 /gcc | |
parent | a8d7041a307a92daf512f1b076832834cdb16c9b (diff) | |
download | gcc-bb4586d38825faf532f8dd12c73049410563ee7c.zip gcc-bb4586d38825faf532f8dd12c73049410563ee7c.tar.gz gcc-bb4586d38825faf532f8dd12c73049410563ee7c.tar.bz2 |
re PR c++/47999 ([C++0x] auto type deduction works incorrectly in a function template)
PR c++/47999
* semantics.c (finish_call_expr): Preserve reference semantics
in templates.
From-SVN: r171053
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/auto22.C | 21 |
4 files changed, 36 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2c28977..ed5dcd8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2011-03-16 Jason Merrill <jason@redhat.com> + PR c++/47999 + * semantics.c (finish_call_expr): Preserve reference semantics + in templates. + * call.c (convert_default_arg): Use LOOKUP_IMPLICIT. 2011-03-16 Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 53497f3..ce24d46 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2150,11 +2150,17 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual, /* A call where the function is unknown. */ result = cp_build_function_call_vec (fn, args, complain); - if (processing_template_decl) + if (processing_template_decl && result != error_mark_node) { + if (TREE_CODE (result) == INDIRECT_REF) + result = TREE_OPERAND (result, 0); + gcc_assert (TREE_CODE (result) == CALL_EXPR + || TREE_CODE (fn) == PSEUDO_DTOR_EXPR + || errorcount); result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); KOENIG_LOOKUP_P (result) = koenig_p; release_tree_vector (orig_args); + result = convert_from_reference (result); } return result; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c345d41..649dc4c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-03-16 Jason Merrill <jason@redhat.com> + + * g++.dg/cpp0x/auto22.C: New. + 2011-03-16 Richard Guenther <rguenther@suse.de> * gcc.dg/guality/vla-1.c (main): Use result of f1 to avoid diff --git a/gcc/testsuite/g++.dg/cpp0x/auto22.C b/gcc/testsuite/g++.dg/cpp0x/auto22.C new file mode 100644 index 0000000..66630e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto22.C @@ -0,0 +1,21 @@ +// PR c++/47999 +// { dg-options -std=c++0x } + +int& identity(int& i) +{ + return i; +} + +// In a function template, auto type deduction works incorrectly. +template <typename = void> +void f() +{ + int i = 0; + auto&& x = identity(i); // Type of x should be `int&`, but it is `int&&`. +} + +int main (int argc, char* argv[]) +{ + f(); + return 0; +} |