From 1dba0da21fc9e113791a7cddc6ff9f0e9cbb63c9 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Wed, 23 Feb 2005 21:17:24 +0000 Subject: [PATCH] fix bug 86336 --- .../core/parser/tests/ast2/AST2CPPTests.java | 20 ++++++++++++++++++ .../core/dom/parser/cpp/CPPSemantics.java | 21 +++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index a9d6dfe575a..60e085f0ba6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -2068,5 +2068,25 @@ public class AST2CPPTests extends AST2BaseTest { IASTReturnStatement r = (IASTReturnStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0]; assertTrue( r.getReturnValue() instanceof IASTCastExpression ); } + + public void testBug86336() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("struct T1 { \n"); //$NON-NLS-1$ + buffer.append(" T1 operator() ( int x ) { \n"); //$NON-NLS-1$ + buffer.append(" return T1(x); \n"); //$NON-NLS-1$ + buffer.append(" } \n"); //$NON-NLS-1$ + buffer.append(" T1( int ) {} \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + tu.getVisitor().visitTranslationUnit(col); + + ICPPConstructor T1_ctor = (ICPPConstructor) col.getName(6).resolveBinding(); + ICPPClassType T1 = (ICPPClassType) col.getName(0).resolveBinding(); + + assertInstances( col, T1_ctor, 2 ); + assertInstances( col, T1, 2 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 199856b29e6..16bff29a2a5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -80,6 +80,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; @@ -169,7 +170,8 @@ public class CPPSemantics { IASTNode p2 = p1.getParent(); return ( ( p1 instanceof ICPPASTQualifiedName && p2 instanceof IASTDeclarator ) || - ( p1 instanceof IASTDeclarator && p2 instanceof IASTSimpleDeclaration) ); + ( p1 instanceof IASTDeclarator && p2 instanceof IASTSimpleDeclaration) || + ( p1 instanceof IASTDeclarator && p2 instanceof IASTFunctionDefinition)); } public boolean considerConstructors(){ if( astName == null ) return false; @@ -1146,7 +1148,7 @@ public class CPPSemantics { temp = ((IASTName) o).resolveBinding(); else if( o instanceof IBinding ){ temp = (IBinding) o; - if( !declaredBefore( temp, name ) ) + if( !( temp instanceof ICPPMember ) && !declaredBefore( temp, name ) ) continue; } else continue; @@ -1286,7 +1288,12 @@ public class CPPSemantics { } static private IType getSourceParameterType( Object [] params, int idx ){ - if( params instanceof IASTExpression [] ){ + if( params instanceof IType[] ){ + IType [] types = (IType[]) params; + if( idx < types.length ) + return types[idx]; + return (idx == 0 ) ? VOID_TYPE : null; + } else if( params instanceof IASTExpression [] ){ IASTExpression [] exps = (IASTExpression[]) params; if( idx < exps.length) return CPPVisitor.getExpressionType( exps[ idx ] ); @@ -1301,7 +1308,7 @@ public class CPPSemantics { return null; } static private IBinding resolveFunction( CPPSemantics.LookupData data, IBinding[] fns ) throws DOMException{ - fns = (IBinding[]) ArrayUtil.trim( IBinding.class, fns ); + fns = (IBinding[]) ArrayUtil.trim( IBinding.class, fns, true ); if( fns == null || fns.length == 0 ) return null; @@ -1348,7 +1355,7 @@ public class CPPSemantics { numSourceParams = 1; sourceParameters = data.functionParameters; - for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ + outer: for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ currFn = (IFunction) fns[fnIdx]; if( currFn == null || bestFn == currFn ) @@ -1379,6 +1386,8 @@ public class CPPSemantics { for( int j = 0; j < numSourceParams || j == 0; j++ ){ source = getSourceParameterType( sourceParameters, j ); + if( source == null ) + continue outer; if( source instanceof IProblemBinding ) return (IBinding) source; @@ -1742,7 +1751,7 @@ public class CPPSemantics { if( t instanceof ICPPClassType ){ LookupData data = new LookupData( EMPTY_NAME_ARRAY ); data.forUserDefinedConversion = true; - data.functionParameters = new Object [] { source }; + data.functionParameters = new IType [] { source }; ICPPConstructor [] constructors = ((ICPPClassType)t).getConstructors(); if( constructors.length > 0 ){