1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

fix bug 86336

This commit is contained in:
Andrew Niefer 2005-02-23 21:17:24 +00:00
parent ad1ab8d1d2
commit 1dba0da21f
2 changed files with 35 additions and 6 deletions

View file

@ -2068,5 +2068,25 @@ public class AST2CPPTests extends AST2BaseTest {
IASTReturnStatement r = (IASTReturnStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0]; IASTReturnStatement r = (IASTReturnStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0];
assertTrue( r.getReturnValue() instanceof IASTCastExpression ); 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 );
}
} }

View file

@ -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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding; 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.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.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
@ -169,7 +170,8 @@ public class CPPSemantics {
IASTNode p2 = p1.getParent(); IASTNode p2 = p1.getParent();
return ( ( p1 instanceof ICPPASTQualifiedName && p2 instanceof IASTDeclarator ) || 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(){ public boolean considerConstructors(){
if( astName == null ) return false; if( astName == null ) return false;
@ -1146,7 +1148,7 @@ public class CPPSemantics {
temp = ((IASTName) o).resolveBinding(); temp = ((IASTName) o).resolveBinding();
else if( o instanceof IBinding ){ else if( o instanceof IBinding ){
temp = (IBinding) o; temp = (IBinding) o;
if( !declaredBefore( temp, name ) ) if( !( temp instanceof ICPPMember ) && !declaredBefore( temp, name ) )
continue; continue;
} else } else
continue; continue;
@ -1286,7 +1288,12 @@ public class CPPSemantics {
} }
static private IType getSourceParameterType( Object [] params, int idx ){ 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; IASTExpression [] exps = (IASTExpression[]) params;
if( idx < exps.length) if( idx < exps.length)
return CPPVisitor.getExpressionType( exps[ idx ] ); return CPPVisitor.getExpressionType( exps[ idx ] );
@ -1301,7 +1308,7 @@ public class CPPSemantics {
return null; return null;
} }
static private IBinding resolveFunction( CPPSemantics.LookupData data, IBinding[] fns ) throws DOMException{ 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 ) if( fns == null || fns.length == 0 )
return null; return null;
@ -1348,7 +1355,7 @@ public class CPPSemantics {
numSourceParams = 1; numSourceParams = 1;
sourceParameters = data.functionParameters; sourceParameters = data.functionParameters;
for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ outer: for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){
currFn = (IFunction) fns[fnIdx]; currFn = (IFunction) fns[fnIdx];
if( currFn == null || bestFn == currFn ) if( currFn == null || bestFn == currFn )
@ -1379,6 +1386,8 @@ public class CPPSemantics {
for( int j = 0; j < numSourceParams || j == 0; j++ ){ for( int j = 0; j < numSourceParams || j == 0; j++ ){
source = getSourceParameterType( sourceParameters, j ); source = getSourceParameterType( sourceParameters, j );
if( source == null )
continue outer;
if( source instanceof IProblemBinding ) if( source instanceof IProblemBinding )
return (IBinding) source; return (IBinding) source;
@ -1742,7 +1751,7 @@ public class CPPSemantics {
if( t instanceof ICPPClassType ){ if( t instanceof ICPPClassType ){
LookupData data = new LookupData( EMPTY_NAME_ARRAY ); LookupData data = new LookupData( EMPTY_NAME_ARRAY );
data.forUserDefinedConversion = true; data.forUserDefinedConversion = true;
data.functionParameters = new Object [] { source }; data.functionParameters = new IType [] { source };
ICPPConstructor [] constructors = ((ICPPClassType)t).getConstructors(); ICPPConstructor [] constructors = ((ICPPClassType)t).getConstructors();
if( constructors.length > 0 ){ if( constructors.length > 0 ){