1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Bug 502016 - Enumeration defined in alias-declaration

Change-Id: I4552b3117008bff7f1269aa3a12e9711e0c8681f
This commit is contained in:
Nathan Ridge 2016-09-22 15:22:05 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 29ae1df652
commit 4470a7a5bb
2 changed files with 30 additions and 7 deletions

View file

@ -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

View file

@ -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();
@ -1814,6 +1816,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
* lookups the method assumes that transitive directives have been stored in the lookup-data.