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

Bug 337583

Summary: Index cannot maintain different typedefs with the same name
Product: [Tools] CDT Reporter: Andrew Gvozdev <angvoz.dev>
Component: cdt-indexerAssignee: Project Inbox <cdt-indexer-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: major    
Priority: P3 CC: aegges, alvaro.sanchez-leon, callahdev, cdtdoug, elliott.partridge, gonwan, kis36205, malaperle, martin.gerhardy, Oliver_Loidl, simon.marchi, veit.scharf, yevshif, y_anitha
Version: 8.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 421014, 439553, 490778, 497867, 533259, 520322    
Attachments:
Description Flags
sample project none

Description Andrew Gvozdev CLA 2011-02-18 11:24:27 EST
When typedefs with the same name are defined in different files parser fails to follow #include strictly and matches wrong typedef (or thinks its ambiguous).

include/file.h:
typedef struct {
	int x;
} SS;

file.c:
#include "include/file.h"
void fun() {
	SS var;
	var.x;
}

Import the attached sample project, reindex and open file.c:
- "var.x" triggers an error "x cannot be resolved"
- content assist on "var." adds "y" instead
- F3 on "SS" gives a popup with 2 choices.

That should not be happening as there is explicit #include "include/file.h" pointing to the proper header.

This problem is pretty severe for big projects and given a chance Codan with the default settings generates tens of thousands of errors for the kinds of projects we are using.
Comment 1 Andrew Gvozdev CLA 2011-02-18 11:25:31 EST
Created attachment 189293 [details]
sample project
Comment 2 Markus Schorn CLA 2011-03-02 05:05:06 EST
Actually the index just maintains a single version for each typedef name. In your example it happens to point to the anonymous struct in file 'other.h', because this file was indexed at a later point.

Because classes, structs and unions can be fwd-declared, we cannot determine whether the same name is meant to name the same type or not. Therefore, there is only one definition for a type-name in the index.

However, there are no fwd-declarations for typedefs and therefore it should be possible to track different version for typedefs with the same name.
Comment 3 Marc-André Laperle CLA 2011-06-27 18:16:10 EDT
*** Bug 350479 has been marked as a duplicate of this bug. ***
Comment 4 Marc-André Laperle CLA 2014-06-27 09:35:29 EDT
*** Bug 438305 has been marked as a duplicate of this bug. ***
Comment 5 Marc-André Laperle CLA 2015-11-04 10:12:22 EST
*** Bug 481283 has been marked as a duplicate of this bug. ***
Comment 6 Nathan Ridge CLA 2018-01-26 02:41:01 EST
*** Bug 530348 has been marked as a duplicate of this bug. ***
Comment 7 Devin Callahan CLA 2020-12-18 13:49:46 EST
*** Bug 520322 has been marked as a duplicate of this bug. ***