Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354599 - ISourceCodeParser.parse() throws exception when parsing one C++ source code.
Summary: ISourceCodeParser.parse() throws exception when parsing one C++ source code.
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: 8.0.1   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 06:13 EDT by Alfred Wang CLA
Modified: 2011-08-18 06:35 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.