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

Bug 354599

Summary: ISourceCodeParser.parse() throws exception when parsing one C++ source code.
Product: [Tools] CDT Reporter: Alfred Wang <alfred.wang>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: critical    
Priority: P3 CC: cdtdoug
Version: 8.0   
Target Milestone: 8.0.1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Alfred Wang CLA 2011-08-12 06:13:33 EDT
The source code is as follows:

template <int T1>
struct dt
{
    template <int T>
    dt<T> operator +(const dt<T> input)
    {
    }
};

dt<3> func1(dt<3> input)
{
    return input;
}


int dut()
{
    dt<3> const_zero;

    dt<3> lll = (func1(func1(const_zero))) + func1(const_zero);
    dt<3> kkk = (func1(func1(const_zero))) + func1(const_zero);

    return 1;
}

I have debugged this code and find that this bug maybe is caused by wrong node generation in AST tree. One node called CPPASTAmbiguousBinaryVsCastExpression is incorrectly added to AST.
Comment 1 Markus Schorn CLA 2011-08-16 09:59:48 EDT
Putting the code above into the CDT editor does not trigger an error. How do you trigger the error? What kind of exception is thrown (a stack trace could help)? What version of CDT are you using?
Comment 2 Alfred Wang CLA 2011-08-17 22:30:23 EDT
(In reply to comment #1)
> Putting the code above into the CDT editor does not trigger an error. How do
> you trigger the error? What kind of exception is thrown (a stack trace could
> help)? What version of CDT are you using?

I only use the CDT core part, org.eclipse.cdt.core_5.3.0.201106081058.jar and attach the source file, org.eclipse.cdt.core.source_5.3.0.201106081058.jar, to eclipse for debugging. 

Here is my parse code: 'filename' is the path of the source code.
FileContent codeReader = FileContent.createForExternalFileLocation(filename);

ScannerInfo scannerInfo = new ScannerInfo();
IScannerExtensionConfiguration configuration = GPPScannerExtensionConfiguration.getInstance();

IScanner scanner = new CPreprocessor(codeReader, scannerInfo, ParserLanguage.CPP,
				 NULL_LOG, configuration,IncludeFileContentProvider.getSavedFilesProvider());

ICPPParserExtensionConfiguration config = new GPPParserExtensionConfiguration();
ISourceCodeParser parser = new GNUCPPSourceParser(scanner,
					ParserMode.COMPLETE_PARSE, NULL_LOG, config);

IASTTranslationUnit tu = parser2.parse();//This line will throw exception. I debug into it step by step.

The stack trace will be:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/icu/text/MessageFormat
    at org.eclipse.cdt.internal.core.dom.parser.ProblemBinding.getMessage(ProblemBinding.java:109)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase$RecursionResolvingBinding.<init>(CPPASTNameBase.java:45)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolvePreBinding(CPPASTNameBase.java:72)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.addCandidate(CPPScope.java:307)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.getBindingsInAST(CPPScope.java:280)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.getBindings(CPPScope.java:207)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.getBindingsFromScope(CPPSemantics.java:1221)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.lookup(CPPSemantics.java:943)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveBinding(CPPSemantics.java:255)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.resolveBinding(CPPVisitor.java:1243)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:278)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName.createIntermediateBinding(CPPASTName.java:63)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolvePreBinding(CPPASTNameBase.java:74)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.getFunctionSetType(ExpressionTypes.java:111)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeOrFunctionSet(ExpressionTypes.java:79)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData.getFunctionArgumentTypes(LookupData.java:557)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.getAssociatedScopes(CPPSemantics.java:660)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.doKoenigLookup(CPPSemantics.java:553)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveBinding(CPPSemantics.java:259)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.resolveBinding(CPPVisitor.java:1243)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:278)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName.createIntermediateBinding(CPPASTName.java:63)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolvePreBinding(CPPASTNameBase.java:74)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression.getExpressionType(CPPASTFunctionCallExpression.java:232)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeOrFunctionSet(ExpressionTypes.java:83)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData.getFunctionArgumentTypes(LookupData.java:557)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.getAssociatedScopes(CPPSemantics.java:660)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.doKoenigLookup(CPPSemantics.java:553)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveBinding(CPPSemantics.java:259)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.resolveBinding(CPPVisitor.java:1243)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:278)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName.createIntermediateBinding(CPPASTName.java:63)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolvePreBinding(CPPASTNameBase.java:74)
    at org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode.resolveAmbiguity(ASTAmbiguousNode.java:116)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguityResolver.visit(CPPASTAmbiguityResolver.java:59)
    at org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode.accept(ASTAmbiguousNode.java:60)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement.accept(CPPASTCompoundStatement.java:79)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition.accept(CPPASTFunctionDefinition.java:187)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguityResolver.leave(CPPASTAmbiguityResolver.java:149)
    at org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.accept(ASTTranslationUnit.java:282)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit.resolveAmbiguities(CPPASTTranslationUnit.java:181)
    at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.resolveAmbiguities(AbstractGNUSourceCodeParser.java:669)
    at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parse(AbstractGNUSourceCodeParser.java:656)
    at autopilot.sourceprocessor.CParser.parse(CParser.java:515)
    at autopilot.sourceprocessor.CParser.parseTranslationUnit(CParser.java:225)
    at autopilot.sourceprocessor.CParser.main(CParser.java:140)

The version I use is part of information for this PR. It's CDT8 on linux.
Comment 3 Markus Schorn CLA 2011-08-18 05:27:41 EDT
Apperently you are using the parser in a non-standard way and you do not provide the class 'com/ibm/icu/text/MessageFormat'

Nevertheless the code snippet is interesting, because the 'RecursionResolvingBinding' should not be created.
Comment 4 Markus Schorn CLA 2011-08-18 05:49:49 EDT
Added testcase and fix. You should still make sure that your JVM can load the class 'com/ibm/icu/text/MessageFormat'.
Comment 5 Alfred Wang CLA 2011-08-18 06:19:11 EDT
(In reply to comment #3)
> Apperently you are using the parser in a non-standard way and you do not
> provide the class 'com/ibm/icu/text/MessageFormat'
> 
> Nevertheless the code snippet is interesting, because the
> 'RecursionResolvingBinding' should not be created.


What do you mean a non-standard way? Could you detail it? Thanks.
Comment 6 CDT Genie CLA 2011-08-18 06:23:03 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 354599: Ambiguity resolution to correctly add parameters into scope cache.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=623b9132819c9dbd49484104ef5c78d409a48ec6
Comment 7 CDT Genie CLA 2011-08-18 06:23:04 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 354599: Ambiguity resolution to correctly add parameters into scope cache.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=1b18d2f29c62c3b18a5597fcd6ce4d43bfe00742
Comment 8 Markus Schorn CLA 2011-08-18 06:35:54 EDT
(In reply to comment #5)
> What do you mean a non-standard way? Could you detail it? Thanks.
Normally you use CDT within an eclipse application, which will take care of loading the necessary bundles. Since you do not do that, you have to provide the necessary jars yourself.