1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 92882: report problem for method definition not matching declaration

This commit is contained in:
Andrew Niefer 2005-04-27 19:29:36 +00:00
parent 6f38f94b90
commit 37e8015bf2
7 changed files with 72 additions and 37 deletions

View file

@ -2308,7 +2308,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
buffer.append("namespace R {\n"); //$NON-NLS-1$
buffer.append("void Q::V::g() { } // error: R doesn’t enclose Q\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
}
/**
@ -10181,7 +10181,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
}
// explicit specialization syntax not used for a member of
// explicitly specialized class template specialization
void A<int>::f() { }
void A<int>::f(int) { }
--End Example]
*/
public void test14_7_3s5() throws Exception {
@ -10199,7 +10199,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("// explicit specialization syntax not used for a member of\n"); //$NON-NLS-1$
buffer.append("// explicitly specialized class template specialization\n"); //$NON-NLS-1$
buffer.append("void A<int>::f() { }\n"); //$NON-NLS-1$
buffer.append("void A<int>::f(int) { }\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}

View file

@ -3797,5 +3797,20 @@ public class AST2CPPTests extends AST2BaseTest {
String code = "struct A { A(); A(const A&) throw(1); ~A() throw(X); };"; //$NON-NLS-1$
parse( code, ParserLanguage.CPP, true, false );
}
public void testBug92882() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class Dummy { int v(); int d; }; \n"); //$NON-NLS-1$
buffer.append("void Dummy::v( int ){ d++; } \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
assertTrue( col.getName(5).resolveBinding() instanceof IProblemBinding );
ICPPField d1 = (ICPPField) col.getName(2).resolveBinding();
ICPPField d2 = (ICPPField) col.getName(7).resolveBinding();
assertSame( d1, d2 );
}
}

View file

@ -113,5 +113,7 @@ public interface IProblemBinding extends IBinding, IScope, IType {
*/
public static final int SEMANTIC_INVALID_REDECLARATION = 0x00C;
public static final int LAST_PROBLEM = SEMANTIC_INVALID_REDECLARATION;
public static final int SEMANTIC_MEMBER_DECLARATION_NOT_FOUND = 0x00D;
public static final int LAST_PROBLEM = SEMANTIC_MEMBER_DECLARATION_NOT_FOUND;
}

View file

@ -63,6 +63,7 @@ public class ProblemBinding implements IProblemBinding, IType, IScope {
errorMessages[SEMANTIC_INVALID_REDEFINITION - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.invalidRedefinition"); //$NON-NLS-1$
errorMessages[SEMANTIC_INVALID_REDECLARATION - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.invalidRedeclaration"); //$NON-NLS-1$
errorMessages[SEMANTIC_BAD_SCOPE - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.badScope"); //$NON-NLS-1$
errorMessages[SEMANTIC_MEMBER_DECLARATION_NOT_FOUND - 1]= ParserMessages.getString("ASTProblemFactory.error.semantic.dom.memberDeclNotFound"); //$NON-NLS-1$
}
/* (non-Javadoc)

View file

@ -204,10 +204,16 @@ public class CPPSemantics {
if( astName == null ) return false;
if( astName.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return false;
IASTNode p1 = astName.getParent();
while( p1 instanceof IASTName )
IASTName n = astName;
if( n.getParent() instanceof ICPPASTTemplateId )
n = (IASTName) n.getParent();
IASTNode p1 = n.getParent();
if( p1 instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)p1).getNames();
if( ns[ns.length - 1] != n )
return false;
p1 = p1.getParent();
}
IASTNode p2 = p1.getParent();
return ( ( p1 instanceof IASTDeclarator && p2 instanceof IASTSimpleDeclaration) ||
@ -544,7 +550,6 @@ public class CPPSemantics {
}
}
if( binding != null ) {
IASTName name = data.astName;
if( name.getParent() instanceof ICPPASTTemplateId )
name = (IASTName) name.getParent();
@ -553,6 +558,8 @@ public class CPPSemantics {
if( name == ns [ ns.length - 1] )
name = (IASTName) name.getParent();
}
if( binding != null ) {
if( name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){
IASTNode parent = name.getParent().getParent();
if( parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){
@ -568,8 +575,12 @@ public class CPPSemantics {
addDefinition( binding, data.astName );
}
}
if( binding == null )
if( binding == null ){
if( name instanceof ICPPASTQualifiedName && data.forDefinition() )
binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name );
else
binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name );
}
return binding;
}

View file

@ -143,7 +143,9 @@ public class CPPVisitor {
parent instanceof ICPPASTTemplateId )
{
binding = CPPSemantics.resolveBinding( name );
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName ){
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName &&
((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND )
{
IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames();
if( ns[ ns.length - 1 ] == name )
parent = parent.getParent();
@ -497,6 +499,9 @@ public class CPPVisitor {
binding = function.resolveParameter( param );
} else if( temp instanceof CPPFunctionTemplate ) {
binding = ((CPPFunctionTemplate)temp).resolveFunctionParameter( param );
} else if( temp instanceof IProblemBinding ){
//problems with the function, still create binding for the parameter
binding = new CPPParameter( name );
}
} else if( parent instanceof ICPPASTTemplateDeclaration ) {
return CPPTemplates.createBinding( param );
@ -798,7 +803,6 @@ public class CPPVisitor {
if( node instanceof IASTIdExpression ){
name = ((IASTIdExpression) node).getName();
break;
//return CPPSemantics.resolveBinding( ((IASTIdExpression)node).getName() );
} else if( node instanceof ICPPASTFieldReference ){
name = ((ICPPASTFieldReference)node).getFieldName();
break;
@ -1484,10 +1488,12 @@ public class CPPVisitor {
if( node != null && node.getParent() instanceof IASTFunctionDefinition ){
IASTFunctionDefinition def = (IASTFunctionDefinition) node.getParent();
IASTName fName = def.getDeclarator().getName();
IBinding binding = fName.resolveBinding();
if( binding != null && binding instanceof ICPPMethod ){
if( fName instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)fName).getNames();
fName = ns[ ns.length - 1];
}
IScope s = getContainingScope( fName );
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator();
IScope s = binding.getScope();
if( s instanceof ICPPTemplateScope )
s = s.getParent();
if( s instanceof ICPPClassScope ){
@ -1499,7 +1505,6 @@ public class CPPVisitor {
return type;
}
}
}
} catch (DOMException e) {
return e.getProblem();
}

View file

@ -83,3 +83,4 @@ ASTProblemFactory.error.semantic.dom.labelStatementNotFound=A label statement wa
ASTProblemFactory.error.semantic.dom.invalidRedefinition=Invalid redefinition of the name {0}
ASTProblemFactory.error.semantic.dom.invalidRedeclaration=Invalid redeclaration of the name {0}
ASTProblemFactory.error.semantic.dom.badScope=A scope could not be created to represent the name {0}
ASTProblemFactory.error.semantic.dom.memberDeclNotFound=A declaration could not be found for this member definition: {0}