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

Bug 319492

Summary: ProblemBinding generated for a function containing a parameter with a different declaration and definition
Product: [Tools] CDT Reporter: Marc-André Laperle <malaperle>
Component: cdt-parserAssignee: Project Inbox <cdt-parser-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: yevshif, zeratul976
Version: 7.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Files to reproduce the problem none

Description Marc-André Laperle CLA 2010-07-11 14:04:16 EDT
Created attachment 173980 [details]
Files to reproduce the problem

I have a couple of variables declared and defined like this :

----Vector.h----

class Vector {

};

extern "C" const Vector ZERO;

----Vector4.h----

struct Vector4 {
    float x, y, z, w;
};

----constants.cpp----

#include "Vector4.h"

extern "C"
{
    Vector4 ZERO = { 0.f, 0.f, 0.f, 0.f };
};

----testVector.cpp----
#include "Vector.h"

void testFunc(Vector v)
{

}

int main() {
	testFunc(ZERO); // <-- problem
	return 0;
}

A ProblemBinding is generated because it thinks ZERO is a Vector4 instead of a Vector.
Comment 1 Markus Schorn CLA 2010-07-19 09:17:57 EDT
Here the index behaves like a linker, it identifies the two variables with each other. In many use-cases this will be the expected behavior. I don't see how the indexer could know whether or not two global variables with the same name are supposed to be identifed or not.
Comment 2 Marc-André Laperle CLA 2010-07-30 02:15:15 EDT
(In reply to comment #1)
> Here the index behaves like a linker, it identifies the two variables with each
> other. In many use-cases this will be the expected behavior. I don't see how
> the indexer could know whether or not two global variables with the same name
> are supposed to be identified or not.

Hi Markus, thanks for the reply. I am not very familiar with the parser and the indexer. I will look at the code to better discuss the "issue". If that even makes sense, maybe the candidates should be "kept" and then it would iterate through those and create a correct binding.
Comment 3 Nathan Ridge CLA 2012-01-12 23:01:50 EST
(In reply to comment #1)
> Here the index behaves like a linker, it identifies the two variables with each
> other. In many use-cases this will be the expected behavior. I don't see how
> the indexer could know whether or not two global variables with the same name
> are supposed to be identifed or not.

If they have different types, as in this case, it should be safe to assume that they should not be identified.
Comment 4 Nathan Ridge CLA 2013-12-15 16:40:36 EST
(In reply to Nathan Ridge from comment #3)
> (In reply to comment #1)
> > Here the index behaves like a linker, it identifies the two variables with each
> > other. In many use-cases this will be the expected behavior. I don't see how
> > the indexer could know whether or not two global variables with the same name
> > are supposed to be identifed or not.
> 
> If they have different types, as in this case, it should be safe to assume
> that they should not be identified.

Actually, I think two global variables with the same name should never be identified with each other unless they have the same type AND one of them is marked 'extern'.