Upstream-Status: Inappropriate [Backport] From d1f71a5193dd2b3debd551f3dc0e0d237acf7e81 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 29 Mar 2011 14:25:37 +0000 Subject: [PATCH 029/200] PR c++/47999 * semantics.c (finish_call_expr): Preserve reference semantics in templates. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@171670 138bc75d-0d04-0410-961f-82ee72b054a4 index 3213483..23bb021 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2150,11 +2150,14 @@ 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); 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; 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 +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; +} -- 1.7.0.4