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

Bug 330777

Summary: recursive template instantiation
Product: [Tools] CDT Reporter: Forrest <spamit64>
Component: cdt-indexerAssignee: Project Inbox <cdt-indexer-inbox>
Status: RESOLVED INVALID QA Contact: Markus Schorn <mschorn.eclipse>
Severity: enhancement    
Priority: P3 CC: cdtdoug, yevshif, zeratul976
Version: 7.0.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Forrest CLA 2010-11-22 04:25:23 EST
template <class par1>
class B
{
...
};

template <int par1,int par2>
class C
{
...
};

template <int par1,int par2>
class A
{
typedef B<C<par1,par2>> D;
...
}

In C/C++ projects tab and more importantly for autocompletion,
D must be not just a typedef with nothing inside,
but expanded to
template <int par1,int par2>
class B<C<par1,par2>>
{
};
and have all members and member functions inside.


I work with a library where templates are typedefed inside templates
with a recursion factor of up to 4, so it's really uncomfortable without help from IDE.
Project is imported from automake.
Comment 1 Markus Schorn CLA 2010-11-24 04:06:39 EST
I have completed your example and invoking content assist after 'x.' proposes 'a'.


template <class par1> struct B {
  int a;
};
template <int par1,int par2> struct C {};
template <int par1,int par2> struct A {
  typedef B<C<par1,par2>> D;
};

void test() {
  A<1,2>::D x;
  x.a;   // Content assist after x.
}
Comment 2 Forrest CLA 2010-11-25 10:11:39 EST
(In reply to comment #1)
> I have completed your example and invoking content assist after 'x.' proposes
> 'a'.
> 
> 
> template <class par1> struct B {
>   int a;
> };
> template <int par1,int par2> struct C {};
> template <int par1,int par2> struct A {
>   typedef B<C<par1,par2>> D;
> };
> 
> void test() {
>   A<1,2>::D x;
>   x.a;   // Content assist after x.
> }

Hi Markus,

That wasn't the actual problem code, just a description.
To reproduce the problem, you need to use the library that I'm using:
DUNE http://www.dune-project.org/index.html.

Here's how you can replicate the issue:
   Download:
http://www.dune-project.org/download/2.0/dune-common-2.0.tar.gz
http://www.dune-project.org/download/2.0/dune-grid-2.0.tar.gz
   extract to DUNE directory somewhere.
   while in DUNE directory
./configure, make

launch "dune-common/bin/duneproject" to create a new project:
enter arbitrary name(for example "test"), dependancy on dune-common  dune-grid, arbitrary version and email.
launch "dune-common/bin/dunecontrol --only=test all"
This will configure and make the test project with one source file in the src
directory.

Now in eclipse create a makefile project with existing code and select the
src directory of test.

add following inlclude:

#include <dune/grid/sgrid.hh>

and these lines inside main:

typedef Dune::SGrid<2,2>::LeafGridView A1;
typedef Dune::Grid<2,2,double,Dune::SGridFamily<2,2,double>>::
Partition<Dune::All_Partition>::LeafGridView A2;

Now A1 and A2 are actually the same type, and A2 is even still several
typedef expansions away from the actual type(so eclipse correctly expands 
typedef up to this level, just not after)

But eclipse code assist works with A2::
and doesn't work with A1::

It for sure isn't the issue of the library, as everything compiles and runs
correctly without errors or warnings.
Comment 3 Forrest CLA 2010-11-25 10:13:01 EST
forgot to mark as reopened
Comment 4 Markus Schorn CLA 2011-01-07 04:10:14 EST
I am not working on a linux host, it'd be helpful if you can provide a self-contained example.
Comment 5 Nathan Ridge CLA 2014-05-03 01:45:39 EDT
(In reply to Forrest from comment #2)
> To reproduce the problem, you need to use the library that I'm using:
> DUNE http://www.dune-project.org/index.html.

I tried following your steps to set up a project using this library, but first I got C++11-related compiler errors when trying to build DUNE 2.0, and then, after building DUNE 2.3 (which didn't have errors), an error of the form "ERROR: could not find /dune.module".

As Markus said, it would be best if you provided a self-contained example of the failure. This could take the form of a zipped Eclipse project or workspace, as long as all the dependencies are in the project/workspace.
Comment 6 Nathan Ridge CLA 2017-01-08 13:34:16 EST
If you're still seeing this, please feel free to reopen after providing a complete example.