1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

fix bug 90652

This commit is contained in:
Andrew Niefer 2005-07-20 18:50:36 +00:00
parent 3aa6c3c301
commit 6992f6f248
4 changed files with 80 additions and 53 deletions

View file

@ -179,36 +179,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 10.2-3b):
struct U { static int i; };
struct V : U { };
struct W : U { using U::i; };
struct X : V, W { void foo(); };
void X::foo() {
i; //finds U::i in two ways: as W::i and U::i in V
// no ambiguity because U::i is static
}
--End Example]
*/
public void test10_2s3b() { // TODO raised bug 90652
StringBuffer buffer = new StringBuffer();
buffer.append("struct U { static int i; };\n"); //$NON-NLS-1$
buffer.append("struct V : U { };\n"); //$NON-NLS-1$
buffer.append("struct W : U { using U::i; };\n"); //$NON-NLS-1$
buffer.append("struct X : V, W { void foo(); };\n"); //$NON-NLS-1$
buffer.append("void X::foo() {\n"); //$NON-NLS-1$
buffer.append("i; //finds U::i in two ways: as W::i and U::i in V\n"); //$NON-NLS-1$
buffer.append("// no ambiguity because U::i is static\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.5.3-1):
template<class T> class task;

View file

@ -5289,6 +5289,32 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
}
/**
[--Start Example(CPP 10.2-3b):
struct U { static int i; };
struct V : U { };
struct W : U { using U::i; };
struct X : V, W { void foo(); };
void X::foo() {
i; //finds U::i in two ways: as W::i and U::i in V
// no ambiguity because U::i is static
}
--End Example]
*/
public void test10_2s3b() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("struct U { static int i; };\n"); //$NON-NLS-1$
buffer.append("struct V : U { };\n"); //$NON-NLS-1$
buffer.append("struct W : U { using U::i; };\n"); //$NON-NLS-1$
buffer.append("struct X : V, W { void foo(); };\n"); //$NON-NLS-1$
buffer.append("void X::foo() {\n"); //$NON-NLS-1$
buffer.append("i; //finds U::i in two ways: as W::i and U::i in V\n"); //$NON-NLS-1$
buffer.append("// no ambiguity because U::i is static\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 10.2-4):
class A {

View file

@ -5049,4 +5049,27 @@ public class AST2CPPTests extends AST2BaseTest {
parseAndCheckBindings( "class Matrix { public: Matrix & operator *(Matrix &); }; Matrix rotate, translate; Matrix transform = rotate * translate;" ); //$NON-NLS-1$
}
public void test10_2s3b() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("struct U { static int i; }; \n"); //$NON-NLS-1$
buffer.append("struct V : U { }; \n"); //$NON-NLS-1$
buffer.append("struct W : U { using U::i; }; \n"); //$NON-NLS-1$
buffer.append("struct X : V, W { void foo(); }; \n"); //$NON-NLS-1$
buffer.append("void X::foo() { \n"); //$NON-NLS-1$
buffer.append(" i; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPField i = (ICPPField) col.getName(1).resolveBinding();
ICPPUsingDeclaration using = (ICPPUsingDeclaration) col.getName(6).resolveBinding();
ICPPDelegate [] delegates = using.getDelegates();
assertEquals( delegates.length, 1 );
assertSame( i, delegates[0].getBinding() );
assertSame( i, col.getName(16).resolveBinding() );
}
}

View file

@ -1236,12 +1236,21 @@ public class CPPSemantics {
}
IBinding binding = ( n instanceof IBinding) ? (IBinding)n : ((IASTName)n).resolveBinding();
while( binding instanceof ICPPDelegate ){
binding = ((ICPPDelegate)binding).getBinding();
}
Object [] objs = ( names instanceof Object[] ) ? (Object[])names : null;
int idx = ( objs != null && objs.length > 0 ) ? 0 : -1;
Object o = ( idx != -1 ) ? objs[idx++] : names;
while( o != null ) {
IBinding b = ( o instanceof IBinding ) ? (IBinding) o : ((IASTName)o).resolveBinding();
if( b instanceof ICPPUsingDeclaration ){
objs = ArrayUtil.append( Object.class, objs, ((ICPPUsingDeclaration)b).getDelegates() );
} else {
while( b instanceof ICPPDelegate ){
b = ((ICPPDelegate)b).getBinding();
}
if( binding != b )
return true;
@ -1265,8 +1274,7 @@ public class CPPSemantics {
}
if( !ok )
return true;
next:
}
if( idx > -1 && idx < objs.length )
o = objs[idx++];
else