1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Bug 491747 - Reference to scoped enumerator declared later in class

Change-Id: If55f0a92c5e3723a306f6ec22a7363c90ef467a8
This commit is contained in:
Nathan Ridge 2016-04-14 21:45:28 -04:00
parent 50eca42cb1
commit a75ce4027b
2 changed files with 23 additions and 1 deletions

View file

@ -11909,4 +11909,15 @@ public class AST2CPPTests extends AST2TestBase {
public void testShadowingAliasDeclaration_484200() throws Exception {
parseAndCheckBindings();
}
// struct S {
// void foo() {
// bar(E::A); // ERROR: Symbol 'A' could not be resolved
// }
// enum class E { A };
// void bar(E);
// };
public void testEnumDeclaredLaterInClass_491747() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -17,6 +17,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -27,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
@ -261,12 +263,21 @@ abstract public class CPPScope implements ICPPASTInternalScope {
return ArrayUtil.trim(result);
}
private boolean isInsideClassScope(IScope scope) {
try {
return scope instanceof ICPPClassScope
|| (scope instanceof ICPPEnumScope && scope.getParent() instanceof ICPPClassScope);
} catch (DOMException e) {
return false;
}
}
private IBinding[] addCandidate(Object candidate, ScopeLookupData lookup, IBinding[] result) {
final IASTNode point = lookup.getLookupPoint();
if (!lookup.isIgnorePointOfDeclaration()) {
IASTTranslationUnit tu= point.getTranslationUnit();
if (!CPPSemantics.declaredBefore(candidate, point, tu != null && tu.getIndex() != null)) {
if (!(this instanceof ICPPClassScope) || !LookupData.checkWholeClassScope(lookup.getLookupName()))
if (!isInsideClassScope(this) || !LookupData.checkWholeClassScope(lookup.getLookupName()))
return result;
}
}