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 41c4b0669f6..61649f91dfc 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 @@ -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): struct A { }; // implicitlydeclared A::operator= 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 fc401ecb25b..7c31b7622b2 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 @@ -5896,78 +5896,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { buffer.append("}\n"); //$NON-NLS-1$ 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): 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("// not the member type X\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - parse(buffer.toString(), ParserLanguage.CPP, true, 0); + parse(buffer.toString(), ParserLanguage.CPP, true, 2); } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java index a4c72a402e8..44312f44d61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java @@ -66,9 +66,12 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind IASTName [] declarations = (IASTName[]) getDeclarations(); if( declarations != null ){ for( int i = 0; i < declarations.length; i++ ){ - IASTDeclaration decl = (IASTDeclaration) declarations[i].getParent(); - if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier ) - return decl; + IASTNode node = declarations[i].getParent(); + while( !(node instanceof IASTDeclaration ) ) + node = node.getParent(); + + if( node.getParent() instanceof ICPPASTCompositeTypeSpecifier ) + return (IASTDeclaration) node; } } 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 1b10b2eb978..c0f0a363dbd 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 @@ -496,8 +496,16 @@ public class CPPSemantics { } if( binding != null ) { - if( data.astName.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){ - IASTNode parent = data.astName.getParent().getParent(); + IASTName name = data.astName; + 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 ){ //don't do a problem here } else { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 69a1bfd047c..fece07adb4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -176,6 +176,8 @@ public class CPPVisitor { return CPPTemplates.createBinding( (ICPPASTTemplateParameter) parent ); } + if( name.toCharArray().length > 0 ) + return binding; return null; }