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

fix bug 90611

there is no ambiguity between a using and its original
This commit is contained in:
Andrew Niefer 2005-04-08 20:26:49 +00:00
parent 6edbe49fa3
commit e3119d2a9d
3 changed files with 82 additions and 72 deletions

View file

@ -201,75 +201,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
} }
} }
/**
[--Start Example(CPP 3.4.3.2-3):
namespace A {
int a;
}
namespace B {
using namespace A;
}
namespace C {
using namespace A;
}
namespace BC {
using namespace B;
using namespace C;
}
void f()
{
BC::a++; //OK: S is { A::a, A::a }
}
namespace D {
using A::a;
}
namespace BD {
using namespace B;
using namespace D;
}
void g()
{
BD::a++; //OK: S is { A::a, A::a }
}
--End Example]
*/
public void test3_4_3_2s3() { // TODO raised bug 90611
StringBuffer buffer = new StringBuffer();
buffer.append("namespace A {\n"); //$NON-NLS-1$
buffer.append("int a;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace B {\n"); //$NON-NLS-1$
buffer.append("using namespace A;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace C {\n"); //$NON-NLS-1$
buffer.append("using namespace A;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace BC {\n"); //$NON-NLS-1$
buffer.append("using namespace B;\n"); //$NON-NLS-1$
buffer.append("using namespace C;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("void f()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("BC::a++; //OK: S is { A::a, A::a }\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace D {\n"); //$NON-NLS-1$
buffer.append("using A::a;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace BD {\n"); //$NON-NLS-1$
buffer.append("using namespace B;\n"); //$NON-NLS-1$
buffer.append("using namespace D;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("void g()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("BD::a++; //OK: S is { A::a, A::a }\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, true);
assertTrue(false);
} catch (Exception e) {
}
}
/** /**
[--Start Example(CPP 6.4-3): [--Start Example(CPP 6.4-3):
int foo() { int foo() {

View file

@ -601,6 +601,72 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, false, false); parse(buffer.toString(), ParserLanguage.CPP, false, false);
} }
/**
[--Start Example(CPP 3.4.3.2-3):
namespace A {
int a;
}
namespace B {
using namespace A;
}
namespace C {
using namespace A;
}
namespace BC {
using namespace B;
using namespace C;
}
void f()
{
BC::a++; //OK: S is { A::a, A::a }
}
namespace D {
using A::a;
}
namespace BD {
using namespace B;
using namespace D;
}
void g()
{
BD::a++; //OK: S is { A::a, A::a }
}
--End Example]
*/
public void test3_4_3_2s3() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("namespace A {\n"); //$NON-NLS-1$
buffer.append("int a;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace B {\n"); //$NON-NLS-1$
buffer.append("using namespace A;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace C {\n"); //$NON-NLS-1$
buffer.append("using namespace A;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace BC {\n"); //$NON-NLS-1$
buffer.append("using namespace B;\n"); //$NON-NLS-1$
buffer.append("using namespace C;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("void f()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("BC::a++; //OK: S is { A::a, A::a }\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace D {\n"); //$NON-NLS-1$
buffer.append("using A::a;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("namespace BD {\n"); //$NON-NLS-1$
buffer.append("using namespace B;\n"); //$NON-NLS-1$
buffer.append("using namespace D;\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("void g()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("BD::a++; //OK: S is { A::a, A::a }\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, true);
}
/** /**
[--Start Example(CPP 3.4.3.2-4): [--Start Example(CPP 3.4.3.2-4):
namespace B { namespace B {

View file

@ -81,6 +81,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; 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.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; 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;
@ -1418,6 +1419,10 @@ public class CPPSemantics {
} else if( temp instanceof IType ){ } else if( temp instanceof IType ){
if( type == null ){ if( type == null ){
type = temp; type = temp;
} else if( (temp instanceof ICPPDelegate && ((ICPPDelegate)temp).getBinding() == type) ||
(type instanceof ICPPDelegate && ((ICPPDelegate)type).getBinding() == temp) )
{
//ok, delegates are synonyms
} else if( type != temp ) { } else if( type != temp ) {
return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name ); return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
} }
@ -1434,7 +1439,11 @@ public class CPPSemantics {
} else { } else {
if( obj == null ) if( obj == null )
obj = temp; obj = temp;
else if( obj != temp ){ else if( (temp instanceof ICPPDelegate && ((ICPPDelegate)temp).getBinding() == obj) ||
(obj instanceof ICPPDelegate && ((ICPPDelegate)obj).getBinding() == temp) )
{
//ok, delegates are synonyms
} else if( obj != temp ){
return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name ); return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
} }
} }
@ -1666,8 +1675,12 @@ public class CPPSemantics {
outer: 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 ||
( bestFn instanceof ICPPDelegate && ((ICPPDelegate)bestFn).getBinding() == currFn ) ||
( currFn instanceof ICPPDelegate && ((ICPPDelegate)currFn).getBinding() == bestFn ) )
{
continue; continue;
}
IASTNode node = ((ICPPInternalBinding)currFn).getDefinition(); IASTNode node = ((ICPPInternalBinding)currFn).getDefinition();
ICPPASTFunctionDeclarator currDtor = ( node == null ) ? null : (ICPPASTFunctionDeclarator)(( node instanceof ICPPASTFunctionDeclarator ) ? node : node.getParent()); ICPPASTFunctionDeclarator currDtor = ( node == null ) ? null : (ICPPASTFunctionDeclarator)(( node instanceof ICPPASTFunctionDeclarator ) ? node : node.getParent());