mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 92768 - expected invalid type problem
- fix also class cast exception in CPPField.getPrimaryDeclaration
This commit is contained in:
parent
da93b4e50e
commit
241036375c
5 changed files with 95 additions and 78 deletions
|
@ -523,6 +523,81 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
[--Start Example(CPP 11.3-2):
|
||||||
|
class A {
|
||||||
|
public:
|
||||||
|
int z;
|
||||||
|
int z1;
|
||||||
|
};
|
||||||
|
class B : public A {
|
||||||
|
int a;
|
||||||
|
public:
|
||||||
|
int b, c;
|
||||||
|
int bf();
|
||||||
|
protected:
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
class D : private B {
|
||||||
|
int d;
|
||||||
|
public:
|
||||||
|
B::c; //adjust access to B::c
|
||||||
|
B::z; //adjust access to A::z
|
||||||
|
A::z1; //adjust access to A::z1
|
||||||
|
int e;
|
||||||
|
int df();
|
||||||
|
protected:
|
||||||
|
B::x; //adjust access to B::x
|
||||||
|
int g;
|
||||||
|
};
|
||||||
|
class X : public D {
|
||||||
|
int xf();
|
||||||
|
};
|
||||||
|
int ef(D&);
|
||||||
|
int ff(X&);
|
||||||
|
--End Example]
|
||||||
|
*/
|
||||||
|
public void test11_3s2() throws Exception { //bug 92793
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("class A {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("public:\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int z;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int z1;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("};\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("class B : public A {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int a;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("public:\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int b, c;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int bf();\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("protected:\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int y;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("};\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("class D : private B {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int d;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("public:\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("B::c; //adjust access to B::c\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("B::z; //adjust access to A::z\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("A::z1; //adjust access to A::z1\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int e;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int df();\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("protected:\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("B::x; //adjust access to B::x\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int g;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("};\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("class X : public D {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int xf();\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("};\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int ef(D&);\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int ff(X&);\n"); //$NON-NLS-1$
|
||||||
|
try {
|
||||||
|
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||||
|
assertTrue(false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
[--Start Example(CPP 12-1):
|
[--Start Example(CPP 12-1):
|
||||||
struct A { }; // implicitlydeclared A::operator=
|
struct A { }; // implicitlydeclared A::operator=
|
||||||
|
|
|
@ -5897,77 +5897,6 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
[--Start Example(CPP 11.3-2):
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
int z;
|
|
||||||
int z1;
|
|
||||||
};
|
|
||||||
class B : public A {
|
|
||||||
int a;
|
|
||||||
public:
|
|
||||||
int b, c;
|
|
||||||
int bf();
|
|
||||||
protected:
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
};
|
|
||||||
class D : private B {
|
|
||||||
int d;
|
|
||||||
public:
|
|
||||||
B::c; //adjust access to B::c
|
|
||||||
B::z; //adjust access to A::z
|
|
||||||
A::z1; //adjust access to A::z1
|
|
||||||
int e;
|
|
||||||
int df();
|
|
||||||
protected:
|
|
||||||
B::x; //adjust access to B::x
|
|
||||||
int g;
|
|
||||||
};
|
|
||||||
class X : public D {
|
|
||||||
int xf();
|
|
||||||
};
|
|
||||||
int ef(D&);
|
|
||||||
int ff(X&);
|
|
||||||
--End Example]
|
|
||||||
*/
|
|
||||||
public void test11_3s2() throws Exception {
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append("class A {\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("public:\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int z;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int z1;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("};\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("class B : public A {\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int a;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("public:\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int b, c;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int bf();\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("protected:\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int x;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int y;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("};\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("class D : private B {\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int d;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("public:\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("B::c; //adjust access to B::c\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("B::z; //adjust access to A::z\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("A::z1; //adjust access to A::z1\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int e;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int df();\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("protected:\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("B::x; //adjust access to B::x\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int g;\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("};\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("class X : public D {\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int xf();\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("};\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int ef(D&);\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int ff(X&);\n"); //$NON-NLS-1$
|
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
[--Start Example(CPP 11.4-1):
|
[--Start Example(CPP 11.4-1):
|
||||||
class X {
|
class X {
|
||||||
|
@ -9488,7 +9417,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
buffer.append("typename T::X x; // illformed: finds the data member X\n"); //$NON-NLS-1$
|
buffer.append("typename T::X x; // illformed: finds the data member X\n"); //$NON-NLS-1$
|
||||||
buffer.append("// not the member type X\n"); //$NON-NLS-1$
|
buffer.append("// not the member type X\n"); //$NON-NLS-1$
|
||||||
buffer.append("}\n"); //$NON-NLS-1$
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -66,9 +66,12 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
|
||||||
IASTName [] declarations = (IASTName[]) getDeclarations();
|
IASTName [] declarations = (IASTName[]) getDeclarations();
|
||||||
if( declarations != null ){
|
if( declarations != null ){
|
||||||
for( int i = 0; i < declarations.length; i++ ){
|
for( int i = 0; i < declarations.length; i++ ){
|
||||||
IASTDeclaration decl = (IASTDeclaration) declarations[i].getParent();
|
IASTNode node = declarations[i].getParent();
|
||||||
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
while( !(node instanceof IASTDeclaration ) )
|
||||||
return decl;
|
node = node.getParent();
|
||||||
|
|
||||||
|
if( node.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||||
|
return (IASTDeclaration) node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -496,8 +496,16 @@ public class CPPSemantics {
|
||||||
|
|
||||||
}
|
}
|
||||||
if( binding != null ) {
|
if( binding != null ) {
|
||||||
if( data.astName.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){
|
IASTName name = data.astName;
|
||||||
IASTNode parent = data.astName.getParent().getParent();
|
if( name.getParent() instanceof ICPPASTTemplateId )
|
||||||
|
name = (IASTName) name.getParent();
|
||||||
|
if( name.getParent() instanceof ICPPASTQualifiedName ){
|
||||||
|
IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
|
||||||
|
if( name == ns [ ns.length - 1] )
|
||||||
|
name = (IASTName) name.getParent();
|
||||||
|
}
|
||||||
|
if( name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){
|
||||||
|
IASTNode parent = name.getParent().getParent();
|
||||||
if( parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){
|
if( parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){
|
||||||
//don't do a problem here
|
//don't do a problem here
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -176,6 +176,8 @@ public class CPPVisitor {
|
||||||
return CPPTemplates.createBinding( (ICPPASTTemplateParameter) parent );
|
return CPPTemplates.createBinding( (ICPPASTTemplateParameter) parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( name.toCharArray().length > 0 )
|
||||||
|
return binding;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue