From e3119d2a9de909f85f038046b94d1aace66e3630 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Fri, 8 Apr 2005 20:26:49 +0000 Subject: [PATCH] fix bug 90611 there is no ambiguity between a using and its original --- .../tests/ast2/AST2CPPSpecFailingTest.java | 69 ------------------- .../parser/tests/ast2/AST2CPPSpecTest.java | 66 ++++++++++++++++++ .../core/dom/parser/cpp/CPPSemantics.java | 19 ++++- 3 files changed, 82 insertions(+), 72 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index c87c6af041f..46a68871a93 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -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): int foo() { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index 0d2192dc78b..3a9de521b4c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -601,6 +601,72 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { 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): namespace B { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 13388eee04c..c91893fa009 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -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.ICPPClassType; 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.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -1418,7 +1419,11 @@ public class CPPSemantics { } else if( temp instanceof IType ){ if( type == null ){ type = temp; - } else if( 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 ) { return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name ); } } else if( temp instanceof IFunction ){ @@ -1434,7 +1439,11 @@ public class CPPSemantics { } else { if( obj == null ) 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 ); } } @@ -1666,8 +1675,12 @@ public class CPPSemantics { outer: for( int fnIdx = 0; fnIdx < numFns; 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; + } IASTNode node = ((ICPPInternalBinding)currFn).getDefinition(); ICPPASTFunctionDeclarator currDtor = ( node == null ) ? null : (ICPPASTFunctionDeclarator)(( node instanceof ICPPASTFunctionDeclarator ) ? node : node.getParent());