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:
parent
6f38f94b90
commit
37e8015bf2
7 changed files with 72 additions and 37 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3778,8 +3778,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
ICPPField x2 = (ICPPField) col.getName(3).resolveBinding();
|
||||
assertSame( x, x2 );
|
||||
}
|
||||
|
||||
public void testBug90648() throws ParserException
|
||||
|
||||
public void testBug90648() throws ParserException
|
||||
{
|
||||
IASTTranslationUnit tu = parse( "int f() { int (&ra)[3] = a; }", ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) ||
|
||||
|
@ -543,16 +549,17 @@ public class CPPSemantics {
|
|||
binding = e.getProblem();
|
||||
}
|
||||
|
||||
}
|
||||
if( binding != null ) {
|
||||
IASTName name = data.astName;
|
||||
if( name.getParent() instanceof ICPPASTTemplateId )
|
||||
}
|
||||
IASTName name = data.astName;
|
||||
if( name.getParent() instanceof ICPPASTTemplateId )
|
||||
name = (IASTName) name.getParent();
|
||||
if( name.getParent() instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
|
||||
if( name == ns [ ns.length - 1] )
|
||||
name = (IASTName) name.getParent();
|
||||
if( name.getParent() instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
|
||||
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 )
|
||||
binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name );
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,20 +1488,21 @@ 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 ){
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator();
|
||||
IScope s = binding.getScope();
|
||||
if( s instanceof ICPPTemplateScope )
|
||||
s = s.getParent();
|
||||
if( s instanceof ICPPClassScope ){
|
||||
ICPPClassScope cScope = (ICPPClassScope) s;
|
||||
IType type = cScope.getClassType();
|
||||
if( dtor.isConst() || dtor.isVolatile() )
|
||||
type = new CPPQualifierType(type, dtor.isConst(), dtor.isVolatile() );
|
||||
type = new CPPPointerType( type );
|
||||
return type;
|
||||
}
|
||||
if( fName instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)fName).getNames();
|
||||
fName = ns[ ns.length - 1];
|
||||
}
|
||||
IScope s = getContainingScope( fName );
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator();
|
||||
if( s instanceof ICPPTemplateScope )
|
||||
s = s.getParent();
|
||||
if( s instanceof ICPPClassScope ){
|
||||
ICPPClassScope cScope = (ICPPClassScope) s;
|
||||
IType type = cScope.getClassType();
|
||||
if( dtor.isConst() || dtor.isVolatile() )
|
||||
type = new CPPQualifierType(type, dtor.isConst(), dtor.isVolatile() );
|
||||
type = new CPPPointerType( type );
|
||||
return type;
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
|
|
|
@ -82,4 +82,5 @@ ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound=A declarati
|
|||
ASTProblemFactory.error.semantic.dom.labelStatementNotFound=A label statement was not found for the name {0}
|
||||
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.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}
|
Loading…
Add table
Reference in a new issue