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

Bug 363609

Summary: C++ template class causes CDT indexer to run forever
Product: [Tools] CDT Reporter: alexnet
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 8.1.0   
Target Milestone: 8.1.0   
Hardware: PC   
OS: Linux   
Whiteboard:

Description alexnet CLA 2011-11-11 13:39:15 EST
Build Identifier: Indigo 20110615-0604 (but also occurs with Galileo SR2)

Here is the code that causes the problem:

template<typename T,
	T p1,      T p2,      T p3=T(),  T p4=T(),  T p5=T(),
	T p6=T(),  T p7=T(),  T p8=T(),  T p9=T(),  T p10=T(),
	T p11=T(), T p12=T(), T p13=T(), T p14=T(), T p15=T(),
	T p16=T(), T p17=T(), T p18=T(), T p19=T(), T p20=T()
	>
struct MaxOfN
{
private:
	template<typename X, X x1, X x2>
	struct Max2
	{
		static const X result = (x1>x2)?x1:x2;
	};

public:
	static const T result =

		Max2<T, // p20
		(Max2<T,// p19
		(Max2<T,// p18
		(Max2<T,// p17
		(Max2<T,// p16
		(Max2<T,// p15
		(Max2<T,// p14
		(Max2<T,// p13
		(Max2<T,// p12
		(Max2<T,// p11
		(Max2<T,// p10
		(Max2<T,// p9
		(Max2<T,// p8
		(Max2<T,// p7
		(Max2<T,// p6
		(Max2<T,// p5
		(Max2<T,// p4
		(Max2<T,// p3
		(Max2<T,p1,p2>::result)
		,p3>::result)
		,p4>::result)
		,p5>::result)
		,p6>::result)
		,p7>::result)
		,p8>::result)
		,p9>::result)
		,p10>::result)
		,p11>::result)
		,p12>::result)
		,p13>::result)
		,p14>::result)
		,p15>::result)
		,p16>::result)
		,p17>::result)
		,p18>::result)
		,p19>::result)
		,p20>::result
		;
};

int main()
{
	return MaxOfN<int,1,2>::result;
}



Reproducible: Always

Steps to Reproduce:
1. Place the source code above in a C++ file, eg: main.cpp
2. Create a project with the source file in 1 
3. Enable indexer (Properties, C/C++ General, Indexer, tick Enable project settings specific, tick Enable Indexer) 
4. Indexer will get to a percentage and will remain there indefinately.
5. Unticking Enable Indexer causes eclipse to crash. The only way to come out without eclipse crashing is by commenting the code and then File->exit.
Comment 1 Markus Schorn CLA 2011-11-28 02:12:02 EST
We have exponential complexity for resolving nested ambgiguities between template-ids and binary expressions involving '<' and '>' operators. I have improved the heursistics to avoid more of the potential branches.

Added testcase testNestedTemplateAmbiguity_363609().
Comment 2 CDT Genie CLA 2011-11-28 02:23:02 EST
*** cdt git genie on behalf of Markus Schorn ***

    Bug 363609: Performance issue with nested template ambiguities.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=93285e7f680db002fe1685163a8ba55ed91e949e