mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
fix bug 90652
This commit is contained in:
parent
3aa6c3c301
commit
6992f6f248
4 changed files with 80 additions and 53 deletions
|
@ -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):
|
[--Start Example(CPP 14.5.3-1):
|
||||||
template<class T> class task;
|
template<class T> class task;
|
||||||
|
|
|
@ -5289,6 +5289,32 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, false, 0);
|
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):
|
[--Start Example(CPP 10.2-4):
|
||||||
class A {
|
class A {
|
||||||
|
|
|
@ -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$
|
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() );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1236,37 +1236,45 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
|
|
||||||
IBinding binding = ( n instanceof IBinding) ? (IBinding)n : ((IASTName)n).resolveBinding();
|
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;
|
Object [] objs = ( names instanceof Object[] ) ? (Object[])names : null;
|
||||||
int idx = ( objs != null && objs.length > 0 ) ? 0 : -1;
|
int idx = ( objs != null && objs.length > 0 ) ? 0 : -1;
|
||||||
Object o = ( idx != -1 ) ? objs[idx++] : names;
|
Object o = ( idx != -1 ) ? objs[idx++] : names;
|
||||||
while( o != null ) {
|
while( o != null ) {
|
||||||
IBinding b = ( o instanceof IBinding ) ? (IBinding) o : ((IASTName)o).resolveBinding();
|
IBinding b = ( o instanceof IBinding ) ? (IBinding) o : ((IASTName)o).resolveBinding();
|
||||||
|
|
||||||
if( binding != b )
|
if( b instanceof ICPPUsingDeclaration ){
|
||||||
return true;
|
objs = ArrayUtil.append( Object.class, objs, ((ICPPUsingDeclaration)b).getDelegates() );
|
||||||
|
} else {
|
||||||
|
while( b instanceof ICPPDelegate ){
|
||||||
|
b = ((ICPPDelegate)b).getBinding();
|
||||||
|
}
|
||||||
|
if( binding != b )
|
||||||
|
return true;
|
||||||
|
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
//3.4.5-4 if the id-expression in a class member access is a qualified id... the result
|
//3.4.5-4 if the id-expression in a class member access is a qualified id... the result
|
||||||
//is not required to be a unique base class...
|
//is not required to be a unique base class...
|
||||||
if( binding instanceof ICPPClassType ){
|
if( binding instanceof ICPPClassType ){
|
||||||
IASTNode parent = data.astName.getParent();
|
IASTNode parent = data.astName.getParent();
|
||||||
if( parent instanceof ICPPASTQualifiedName &&
|
if( parent instanceof ICPPASTQualifiedName &&
|
||||||
parent.getPropertyInParent() == IASTFieldReference.FIELD_NAME )
|
parent.getPropertyInParent() == IASTFieldReference.FIELD_NAME )
|
||||||
{
|
{
|
||||||
ok = true;
|
ok = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//it is not ambiguous if they are the same thing and it is static or an enumerator
|
||||||
//it is not ambiguous if they are the same thing and it is static or an enumerator
|
if( binding instanceof IEnumerator ||
|
||||||
if( binding instanceof IEnumerator ||
|
(binding instanceof IFunction && ((ICPPInternalFunction)binding).isStatic( false )) ||
|
||||||
(binding instanceof IFunction && ((ICPPInternalFunction)binding).isStatic( false )) ||
|
(binding instanceof IVariable && ((IVariable)binding).isStatic()) )
|
||||||
(binding instanceof IVariable && ((IVariable)binding).isStatic()) )
|
{
|
||||||
{
|
ok = true;
|
||||||
ok = true;
|
}
|
||||||
|
if( !ok )
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if( !ok )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
next:
|
|
||||||
if( idx > -1 && idx < objs.length )
|
if( idx > -1 && idx < objs.length )
|
||||||
o = objs[idx++];
|
o = objs[idx++];
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue