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

Bug 325135

Summary: Could not find a parameter symbol when used with operator or copy ctor
Product: [Tools] CDT Reporter: Marc-André Laperle <malaperle>
Component: cdt-source-navAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3    
Version: 6.0   
Target Milestone: 7.0.2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Open declaration parameter patch + test
none
extended testcase + fix mschorn.eclipse: iplog-

Description Marc-André Laperle CLA 2010-09-13 12:52:38 EDT
If I Ctrl+click on a variable used with an operator or the copy constructor and it is declared as a parameter, the symbol cannot be found.

Example:

struct Bar;

void bug(Bar name)
{
	Bar foo = name; // cannot find symbol
	Bar foo2(name); // cannot find symbol
	name; // can find symbol
	if(foo == name); // can find symbol
}

void nobug()
{
	const Bar& name;
	Bar foo = name; // can find symbol
	Bar foo2(name); // can find symbol
}
Comment 1 Marc-André Laperle CLA 2010-09-15 17:24:39 EDT
(In reply to comment #0)
>     const Bar& name;

Oops, this line should be 'Bar name;'
Comment 2 Marc-André Laperle CLA 2010-09-15 18:01:02 EDT
This worked in CDT 5.0.2, the bug was introduced in 6.0.0

No need to use a struct, it works with a simple int:

void bug(int var)
{
    // cannot find symbol
    int foo = var;
    int foo2(var);

    // can find symbol
    var;
    foo = var;
    if(foo == var);
    foo * var;
    foo *= var;
}

void nobug()
{
    // can find symbol
    int var;
    int foo = var;
    int foo2(var);
}
Comment 3 Marc-André Laperle CLA 2010-09-15 19:48:15 EDT
Created attachment 178993 [details]
Open declaration parameter patch + test

I think the problem is OpenDeclarationsJob.isInSameFunction calling getEnclosingDeclaration. getEnclosingDeclaration searches for an IASTDeclaration which 'int foo = var;' matches. I think it should look for IASTFunctionDefinition.
Comment 4 Markus Schorn CLA 2010-09-16 04:09:12 EDT
Created attachment 179003 [details]
extended testcase + fix

Thanks Marc!
There is a related problem with template parameters. Therefore I have extended your patch. Also I have changed the implementation of isInSameFunction, such that it is as similar as possible to isInSameTemplate.
Comment 5 Markus Schorn CLA 2010-09-16 04:10:45 EDT
Fixed in 8.0 > 20100916.
Comment 7 Marc-André Laperle CLA 2010-09-17 21:55:18 EDT
(In reply to comment #5)
> Fixed in 8.0 > 20100916.

Thanks! Would it be possible to apply this to 7.0.2?
Comment 8 Markus Schorn CLA 2010-09-20 03:32:58 EDT
(In reply to comment #7)
> Thanks! Would it be possible to apply this to 7.0.2?
Sure, I'll wait until 7.0.1 has been released, though.
Comment 9 Markus Schorn CLA 2010-09-28 02:38:31 EDT
Fixed in 7.0.2 > 20100928.