From 23e918bc086ef4822545ce32d3b547cfae80a01c Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 15 Apr 2009 07:53:22 +0000 Subject: [PATCH] Correct scope for elaborated type specifiers, bug 270831. --- .../cdt/core/parser/tests/ast2/AST2CPPTests.java | 10 ++++++++++ .../cdt/internal/core/dom/parser/cpp/CPPClassType.java | 10 ++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 5c75108467f..cf6a682bc55 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -23,6 +23,7 @@ import java.util.Iterator; import junit.framework.TestSuite; import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil; +import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; @@ -7120,4 +7121,13 @@ public class AST2CPPTests extends AST2BaseTest { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("A a;", 1, ICPPClassType.class); } + + // template class Moo; + // bool getFile(Moo & res); + public void testScopeOfClassFwdDecl_270831() throws Exception { + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + ICPPClassType t= ba.assertNonProblem("Foo", 3, ICPPClassType.class); + IScope scope= t.getScope(); + assertEquals(EScopeKind.eGlobal, scope.getKind()); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 030f6ba95d7..7dc6a1e6bb8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -20,10 +20,8 @@ import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -268,10 +266,10 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp IScope scope = CPPVisitor.getContainingScope(name); if (definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) { IASTNode node = declarations[0].getParent().getParent(); - if (node instanceof IASTFunctionDefinition || node instanceof IASTParameterDeclaration || - (node instanceof IASTSimpleDeclaration && - (((IASTSimpleDeclaration) node).getDeclarators().length > 0 || getElaboratedTypeSpecifier().isFriend()))) - { + if (node instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration) node).getDeclarators().length == 0 + && !getElaboratedTypeSpecifier().isFriend()) { + // 3.3.1.5 class-key identifier ; + } else { while(scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) { try { scope = scope.getParent();