From 09ab420f17873f79335ffdb226d5ca5344c90d45 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Sun, 12 Feb 2023 00:51:11 +0300 Subject: [PATCH] Actually apply type conversion in CPPEvaluation maybeApplyConversion() Currently type of parameters of instantiated template function is ignored while preparing activation record, which makes constexpr evaluation of instantiated body use types of arguments in function call expression instead: template bool f(T t) { return t > 0; } t(-1); // CDT returns false because conversion is not done Fix this by applying EvalTypeId to argument if cost of standard conversions is Rank.CONVERSION to make sure createActivationRecord() would populate activation record with argument values matching template parameter types. --- .../core/dom/parser/cpp/semantics/CPPEvaluation.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index bb631bb9198..c25776b0255 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2014 Google, Inc and others. + * Copyright (c) 2012, 2014, 2023 Google, Inc and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,6 +11,7 @@ * Contributors: * Sergey Prigogin (Google) - initial API and implementation * Nathan Ridge + * Igor V. Kovalenko *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -34,6 +35,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.Rank; import org.eclipse.core.runtime.CoreException; public abstract class CPPEvaluation implements ICPPEvaluation { @@ -207,9 +209,12 @@ public abstract class CPPEvaluation implements ICPPEvaluation { // Source type is not a class type, or is but a conversion operator wasn't used. // Check for standard conversions. - if (!Conversions.checkImplicitConversionSequence(targetType, type, valueCategory, UDCMode.FORBIDDEN, - Context.ORDINARY).converts()) { + Cost cost = Conversions.checkImplicitConversionSequence(targetType, type, valueCategory, UDCMode.FORBIDDEN, + Context.ORDINARY); + if (!cost.converts()) { return EvalFixed.INCOMPLETE; + } else if (cost.getRank() == Rank.CONVERSION) { + return new EvalTypeId(targetType, argument.getTemplateDefinition(), false, false, argument); } } catch (DOMException e) { CCorePlugin.log(e);