Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352268

Summary: A function with a reference parameter is not resolved when the parameter is a return value from another function
Product: [Tools] CDT Reporter: Gil Barash <scobido1984>
Component: cdt-parserAssignee: Project Inbox <cdt-parser-inbox>
Status: RESOLVED INVALID QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, malaperle
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Gil Barash CLA 2011-07-16 07:44:37 EDT
Build Identifier: Eclipse I20110613-1736 CDT 8.0

See steps to reproduce below...
(The code compiles and works fine under VC++ compiler)

Reproducible: Always

Steps to Reproduce:
Writing the following code causes "foo" to be unresolved:

class A
{
  int a;
};

int foo(A &p)
{
  return 0;
}

A get()
{
  return A();
}

int main() {
  foo(get()); // <- "foo" not resolved
  return 0;
}
Comment 1 Marc-André Laperle CLA 2011-07-17 15:13:34 EDT
Hmmm, it doesn't compile with gcc 4.5.2 ang clang 2.9 though.

error: invalid initialization of non-const reference of type 'A&' from an rvalue of type 'A'
error: in passing argument 1 of 'int foo(A&)'

If you use /Za (disable language extensions) in VS you should get
Error	2	error C2664: 'foo' : cannot convert parameter 1 from 'A' to 'A &'
Comment 2 Markus Schorn CLA 2011-07-20 03:07:42 EDT
This is invalid c++ code. Microsoft decided not to support this feature in the future, see
http://msdn.microsoft.com/en-us/library/s5b150wd(v=vs.71).aspx