From 0071f546d1e2cf904589984776c0414ebf89afdc Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Thu, 28 Nov 2013 01:10:29 -0500 Subject: [PATCH] Bug 418770 - NPE in EvalBinding.getBinding involving specialized enum Change-Id: Ibbf3c1dd40e3e33a111c5d3a433277a1349dd445 Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/19031 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 25 +++++++++++++++++++ .../cpp/CPPEnumerationSpecialization.java | 8 +++++- .../cpp/PDOMCPPEnumerationSpecialization.java | 5 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 451db29d304..391f8eddb9e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -8122,4 +8122,29 @@ public class AST2TemplateTests extends AST2TestBase { public void testMemberOfPartialSpecialization_416788() throws Exception { parseAndCheckBindings(); } + + // template + // struct enable_if { + // typedef void type; + // }; + // + // template + // struct MyClass { + // enum { + // K + // }; + // + // template + // void method(typename enable_if::type* = 0) { + // } + // }; + // + // int main() { + // MyClass<0> myObject; + // myObject.method<0>(); + // return 0; + // } + public void testSpecializedEnumerator_418770() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java index 8f0c041607d..aefcbfff50e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerationSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Nathan Ridge. + * Copyright (c) 2013 Nathan Ridge and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Nathan Ridge - Initial API and implementation + * Marc-Andre Laperle (Ericsson) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -17,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumerationSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; @@ -93,6 +95,10 @@ public class CPPEnumerationSpecialization extends CPPSpecialization implements I @Override public IEnumerator specializeEnumerator(IEnumerator enumerator) { + if (enumerator instanceof ICPPSpecialization && ((ICPPSpecialization) enumerator).getOwner() == this) { + return enumerator; + } + // The specialized enumerators are already computed, just need // to look up the right one. IEnumerator[] unspecializedEnumerators = getSpecializedBinding().getEnumerators(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerationSpecialization.java index e4e9d451bc0..ffc814affd8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerationSpecialization.java @@ -7,6 +7,7 @@ * * Contributors: * Sergey Prigogin (Google) - initial API and implementation + * Marc-Andre Laperle (Ericsson) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -245,6 +246,10 @@ class PDOMCPPEnumerationSpecialization extends PDOMCPPSpecialization @Override public IEnumerator specializeEnumerator(IEnumerator enumerator) { + if (enumerator instanceof ICPPSpecialization && ((ICPPSpecialization) enumerator).getOwner() == this) { + return enumerator; + } + // The specialized enumerators are already computed, just need to look up the right one. IEnumerator[] unspecializedEnumerators = getSpecializedBinding().getEnumerators(); for (int i = 0; i < unspecializedEnumerators.length; ++i) {