From 4470a7a5bbaedc6fe44b5b0997928f27e3c0ddbd Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Thu, 22 Sep 2016 15:22:05 -0400 Subject: [PATCH] Bug 502016 - Enumeration defined in alias-declaration Change-Id: I4552b3117008bff7f1269aa3a12e9711e0c8681f --- .../core/parser/tests/ast2/AST2CPPTests.java | 11 ++++++++ .../parser/cpp/semantics/CPPSemantics.java | 26 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 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 cee04fa6e66..caa0900b04a 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 @@ -11982,6 +11982,17 @@ public class AST2CPPTests extends AST2TestBase { parseAndCheckBindings(); } + // struct foo { + // using E = enum { Zero, One, Two }; + // + // bool f() { + // return Zero == 0; // "Symbol 'Zero' could not be resolved" + // } + // }; + public void testAnonymousEnumInAliasDeclaration_502016() throws Exception { + parseAndCheckBindings(); + } + // struct S { // void foo() { // bar(E::A); // ERROR: Symbol 'A' could not be resolved diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 1d68d570b0a..7244f86d85a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -1742,12 +1742,7 @@ public class CPPSemantics { ICPPASTEnumerationSpecifier enumeration = (ICPPASTEnumerationSpecifier) declSpec; specName = enumeration.getName(); - // Add unscoped enumerators to the enclosing scope - if (!enumeration.isScoped()) { - for (IASTEnumerator enumerator : enumeration.getEnumerators()) { - ASTInternal.addName(scope, enumerator.getName()); - } - } + handleEnumeration(enumeration, scope); } if (specName != null) { if (!(specName instanceof ICPPASTQualifiedName)) { @@ -1785,8 +1780,15 @@ public class CPPSemantics { IASTName alias = ((ICPPASTNamespaceAlias) declaration).getAlias(); ASTInternal.addName(scope, alias); } else if (declaration instanceof ICPPASTAliasDeclaration) { - IASTName alias = ((ICPPASTAliasDeclaration) declaration).getAlias(); + ICPPASTAliasDeclaration aliasDecl = (ICPPASTAliasDeclaration) declaration; + IASTName alias = aliasDecl.getAlias(); ASTInternal.addName(scope, alias); + + // The mapping-type-id could declare an enumeration. + IASTDeclSpecifier declSpec = aliasDecl.getMappingTypeId().getDeclSpecifier(); + if (declSpec instanceof ICPPASTEnumerationSpecifier) { + handleEnumeration((ICPPASTEnumerationSpecifier) declSpec, scope); + } } else if (declaration instanceof IASTFunctionDefinition) { IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; final IASTDeclSpecifier declSpec = functionDef.getDeclSpecifier(); @@ -1813,6 +1815,16 @@ public class CPPSemantics { } } } + + private static void handleEnumeration(ICPPASTEnumerationSpecifier enumSpec, + IScope enclosingScope) { + // Add unscoped enumerators to the enclosing scope + if (!enumSpec.isScoped()) { + for (IASTEnumerator enumerator : enumSpec.getEnumerators()) { + ASTInternal.addName(enclosingScope, enumerator.getName()); + } + } + } /** * Perform lookup in nominated namespaces that appear in the given scope. For unqualified