Bug 533216 - Avoid a ClassCastException in EvalBinding.unmarshal() if the parameter owner could not be stored in the index

Change-Id: Ic44495420b0489cfeb1e371e2b776b44b57895fe
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java
index 51eca0e..078ed7d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java
@@ -14,6 +14,7 @@
 
 import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType;
 
+import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
 import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
 import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -24,6 +25,7 @@
 import org.eclipse.cdt.core.dom.ast.IEnumerator;
 import org.eclipse.cdt.core.dom.ast.IFunction;
 import org.eclipse.cdt.core.dom.ast.IFunctionType;
+import org.eclipse.cdt.core.dom.ast.IProblemBinding;
 import org.eclipse.cdt.core.dom.ast.IType;
 import org.eclipse.cdt.core.dom.ast.IValue;
 import org.eclipse.cdt.core.dom.ast.IVariable;
@@ -377,7 +379,16 @@
 
 	public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException {
 		if ((firstBytes & ITypeMarshalBuffer.FLAG1) != 0) {
-			ICPPFunction parameterOwner= (ICPPFunction) buffer.unmarshalBinding();
+			IBinding paramOwnerBinding = buffer.unmarshalBinding();
+			if (paramOwnerBinding instanceof IProblemBinding) {
+				// The parameter owner could not be stored in the index.
+				// If this happens, it's almost certainly a bug, but the severity
+				// is mitigated by returning a problem evaluation instead of just
+				// trying to cast to ICPPFunction and throwing a ClassCastException.
+				CCorePlugin.log("An EvalBinding had a parameter owner that could not be stored in the index");  //$NON-NLS-1$
+				return EvalFixed.INCOMPLETE;
+			}
+			ICPPFunction parameterOwner= (ICPPFunction) paramOwnerBinding;
 			int parameterPosition= buffer.getInt();
 			IType type= buffer.unmarshalType();
 			IBinding templateDefinition= buffer.unmarshalBinding();