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

Bug 326070

Summary: No support for references through dependent names.
Product: [Tools] CDT Reporter: John Liu <john_ws_liu>
Component: cdt-parserAssignee: Project Inbox <cdt-parser-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: normal    
Priority: P3 CC: haoqing, jens.elmenthaler, konradsa, mail, subscribe, yevshif, zeratul976
Version: 7.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 536160    

Description John Liu CLA 2010-09-23 11:13:51 EDT
Build Identifier: 

Call hierarchy doesn't work properly for a template function.

In this example code:

//TEMPLATE FUNCTIONS
template <class type>
type retName(type Name){
	return Name;
}

template <class type>
type getName(type Name1){
	type A = retName(Name1);
	return A;
}

int main() {
	getName <int> (6);
	getNum(7);
}

Right click on retName -> call hierarchy, then the result caller list is empty, but getName should be there.

Right click on getName -> call hierarchy, the the result caller list has main function, which is correct, but callee list is empty, retName should be there.

I searched bugzilla bugs for call hierarchy problem related to template to avoid opening a duplicate bug, and found https://bugs.eclipse.org/bugs/show_bug.cgi?id=240589 may be related to it, but not the  exactly  same problem. 


Reproducible: Always
Comment 1 Markus Schorn CLA 2010-09-27 11:43:54 EDT
At this point CDT has no support for references that are made through dependent names. (The parser does not actually instantiate the function-body to resolve names therein.)
Comment 2 Marc-André Laperle CLA 2014-07-10 22:06:26 EDT
*** Bug 436958 has been marked as a duplicate of this bug. ***
Comment 3 Nathan Ridge CLA 2016-12-09 04:58:33 EST
*** Bug 508957 has been marked as a duplicate of this bug. ***
Comment 4 Nathan Ridge CLA 2016-12-09 05:02:30 EST
Note that bug 490475 has added infrastructure for instantiating function bodies. (The motivation there was C++14 constexpr evaluation for function templates, but the infrastructure generalizes to other uses.)

It would be possible to use this infrastructure to record references through dependent names during indexing. However, this would require instantiating all function templates during indexing (not just constexpr ones), which may have a significant performance impact.
Comment 5 Michael Teske CLA 2016-12-12 07:09:56 EST
How about making it optional? I think it would be extremely useful if the indexer could handle templates correctly/completely, even if it would take a while to build that index.
Comment 6 Nathan Ridge CLA 2016-12-12 20:18:15 EST
(In reply to Michael Teske from comment #5)
> How about making it optional? I think it would be extremely useful if the
> indexer could handle templates correctly/completely, even if it would take a
> while to build that index.

Yes, I think this is what we'll need to do. Introduce an option in the indexer preferences to instantiate function bodies, and let users decide if they like the performance / accuracy tradeoff.
Comment 7 Nathan Ridge CLA 2016-12-27 22:38:49 EST
*** Bug 332430 has been marked as a duplicate of this bug. ***
Comment 8 Nathan Ridge CLA 2017-01-05 22:18:17 EST
*** Bug 509986 has been marked as a duplicate of this bug. ***
Comment 9 Nathan Ridge CLA 2017-01-05 22:19:22 EST
If/when we fix this, we should go through the duplicate bugs and make sure the testcases in each of them start working.
Comment 10 Nathan Ridge CLA 2022-02-01 18:00:52 EST
*** Bug 578520 has been marked as a duplicate of this bug. ***