Bug 469023 - UnsupportedOperationException in CPPVisitor.createBinding
authorSergey Prigogin <eclipse.sprigogin@gmail.com>
Mon, 1 Jun 2015 17:24:02 +0000 (10:24 -0700)
committerSergey Prigogin <eclipse.sprigogin@gmail.com>
Mon, 1 Jun 2015 17:24:02 +0000 (10:24 -0700)
Change-Id: I10653fc6a23364d0977d3f7dc6e92b84812bf5bb

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java

index c3e27ab..4f3c31e 100644 (file)
@@ -549,8 +549,9 @@ public class CPPVisitor extends ASTQueries {
                        }
                }
                if (scope instanceof ICPPClassScope && isFriend && !qualified) {
-                       while (scope instanceof ICPPClassScope)
+                       while (scope instanceof ICPPClassScope) {
                                scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
+                       }
                }
                if (scope != null) {
                        binding = scope.getBinding(elabType.getName(), false);
@@ -2500,8 +2501,9 @@ public class CPPVisitor extends ASTQueries {
 
        private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
                IScope parentScope= scope.getParent();
-               // the index cannot return the translation unit as parent scope
-               if (parentScope == null && scope instanceof IIndexScope && unit != null) {
+               // Replace the global scope from index with the global scope of the translation unit.
+               if ((parentScope == null || parentScope.getKind() == EScopeKind.eGlobal) &&
+                               scope instanceof IIndexScope && unit != null) {
                        parentScope= unit.getScope();
                }
                return parentScope;