mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 06:55:23 +02:00
fix bugs 84679, 84686
This commit is contained in:
parent
d2350bf588
commit
b72b0dc75f
3 changed files with 51 additions and 9 deletions
|
@ -1159,16 +1159,35 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertEquals( name.getNames()[2].toString(), "ghi" ); //$NON-NLS-1$
|
assertEquals( name.getNames()[2].toString(), "ghi" ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _test84679() throws Exception {
|
public void testBug84679() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append("namespace Y { void f(float); } // NPE on resolve binding \n"); //$NON-NLS-1$
|
buffer.append("namespace Y { void f(float); } \n"); //$NON-NLS-1$
|
||||||
buffer.append("namespace A { using namespace Y; f(int); } // NPE on resolve binding \n" ); //$NON-NLS-1$
|
buffer.append("namespace A { using namespace Y; f(int); } \n"); //$NON-NLS-1$
|
||||||
buffer.append("namespace B { void f(char); } // NPE on resolve binding \n "); //$NON-NLS-1$
|
buffer.append("namespace B { void f(char); } \n"); //$NON-NLS-1$
|
||||||
buffer.append("namespace AB { using namespace A; using namespace B; } \n"); //$NON-NLS-1$
|
buffer.append("namespace AB { using namespace A; using namespace B; } \n"); //$NON-NLS-1$
|
||||||
buffer.append("void h(){ \n"); //$NON-NLS-1$
|
buffer.append("void h(){ \n"); //$NON-NLS-1$
|
||||||
buffer.append(" AB::f(1); \n"); //$NON-NLS-1$
|
buffer.append(" AB::f(1); \n"); //$NON-NLS-1$
|
||||||
buffer.append(" AB::f(’c’); \n"); //$NON-NLS-1$
|
buffer.append(" AB::f(’c’); \n"); //$NON-NLS-1$
|
||||||
buffer.append("} \n"); //$NON-NLS-1$
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
ICPPNamespace Y = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||||
|
ICPPNamespace A = (ICPPNamespace) col.getName(3).resolveBinding();
|
||||||
|
ICPPNamespace B = (ICPPNamespace) col.getName(7).resolveBinding();
|
||||||
|
ICPPNamespace AB = (ICPPNamespace) col.getName(10).resolveBinding();
|
||||||
|
|
||||||
|
IFunction f = (IFunction) col.getName(16).resolveBinding();
|
||||||
|
IFunction fdef = (IFunction) col.getName(5).resolveBinding();
|
||||||
|
IProblemBinding f2 = (IProblemBinding) col.getName(19).resolveBinding();
|
||||||
|
assertSame( f, fdef );
|
||||||
|
assertEquals( IProblemBinding.SEMANTIC_NAME_NOT_FOUND, f2.getID() );
|
||||||
|
assertInstances( col, Y, 2 );
|
||||||
|
assertInstances( col, A, 2 );
|
||||||
|
assertInstances( col, B, 2 );
|
||||||
|
assertInstances( col, AB, 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug84692() throws Exception {
|
public void testBug84692() throws Exception {
|
||||||
|
@ -1195,5 +1214,23 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertInstances( col, Data, 2 );
|
assertInstances( col, Data, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug84686() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("namespace B { int b; } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("namespace A { using namespace B; int a; } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("namespace B { using namespace A; } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("void f() { B::a++; } \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 11);
|
||||||
|
|
||||||
|
IVariable a1 = (IVariable) col.getName(4).resolveBinding();
|
||||||
|
IVariable a2 = (IVariable) col.getName(10).resolveBinding();
|
||||||
|
assertSame( a1, a2 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ 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.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.ICPPReferenceType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
|
@ -457,7 +458,7 @@ public class CPPSemantics {
|
||||||
ICPPScope scope = getLookupScope( name );
|
ICPPScope scope = getLookupScope( name );
|
||||||
while( scope != null ){
|
while( scope != null ){
|
||||||
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
|
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
|
||||||
if( scope.getPhysicalNode() != blockItem.getParent() )
|
if( scope.getPhysicalNode() != blockItem.getParent() && !(scope instanceof ICPPNamespaceScope) )
|
||||||
blockItem = node;
|
blockItem = node;
|
||||||
|
|
||||||
List directives = null;
|
List directives = null;
|
||||||
|
@ -703,7 +704,7 @@ public class CPPSemantics {
|
||||||
namespaceDefs = namespace.getNamespaceDefinitions();
|
namespaceDefs = namespace.getNamespaceDefinitions();
|
||||||
|
|
||||||
nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[0].getParent()).getDeclarations();
|
nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[0].getParent()).getDeclarations();
|
||||||
namespaceIdx = -1;
|
namespaceIdx = 0;
|
||||||
} else if( parent instanceof ICPPASTFunctionDeclarator ){
|
} else if( parent instanceof ICPPASTFunctionDeclarator ){
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||||
nodes = dtor.getParameters();
|
nodes = dtor.getParameters();
|
||||||
|
@ -740,7 +741,7 @@ public class CPPSemantics {
|
||||||
if( namespaceIdx > -1 ) {
|
if( namespaceIdx > -1 ) {
|
||||||
//check all definitions of this namespace
|
//check all definitions of this namespace
|
||||||
while( namespaceIdx > -1 && namespaceDefs.length > ++namespaceIdx ){
|
while( namespaceIdx > -1 && namespaceDefs.length > ++namespaceIdx ){
|
||||||
nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[0].getParent()).getDeclarations();
|
nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[namespaceIdx].getParent()).getDeclarations();
|
||||||
if( nodes.length > 0 ){
|
if( nodes.length > 0 ){
|
||||||
idx = 0;
|
idx = 0;
|
||||||
item = nodes[0];
|
item = nodes[0];
|
||||||
|
@ -995,7 +996,7 @@ public class CPPSemantics {
|
||||||
} else {
|
} else {
|
||||||
if( obj == null )
|
if( obj == null )
|
||||||
obj = temp;
|
obj = temp;
|
||||||
else {
|
else if( obj != temp ){
|
||||||
return new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
return new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1200,6 +1201,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 instanceof IProblemBinding )
|
||||||
|
return (IBinding) source;
|
||||||
|
|
||||||
if( j < numTargetParams ){
|
if( j < numTargetParams ){
|
||||||
if( targetLength == 0 && j == 0 ){
|
if( targetLength == 0 && j == 0 ){
|
||||||
|
|
|
@ -1569,6 +1569,8 @@ public class CPPVisitor {
|
||||||
} catch ( DOMException e ) {
|
} catch ( DOMException e ) {
|
||||||
return e.getProblem();
|
return e.getProblem();
|
||||||
}
|
}
|
||||||
|
} else if( binding instanceof IProblemBinding ){
|
||||||
|
return (IType) binding;
|
||||||
}
|
}
|
||||||
} else if( expression instanceof IASTCastExpression ){
|
} else if( expression instanceof IASTCastExpression ){
|
||||||
IASTTypeId id = ((IASTCastExpression)expression).getTypeId();
|
IASTTypeId id = ((IASTCastExpression)expression).getTypeId();
|
||||||
|
|
Loading…
Add table
Reference in a new issue