[Lldb-commits] [lldb] [lldb] Add ternary conditional operator to DIL (PR #211344)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 4 07:55:37 PDT 2026
================
@@ -1578,4 +1578,37 @@ llvm::Expected<lldb::ValueObjectSP> Interpreter::Visit(const CastNode &node) {
node.GetLocation());
}
+llvm::Expected<lldb::ValueObjectSP>
+Interpreter::Visit(const ConditionalNode &node) {
+ auto cond_or_err = EvaluateAndDereference(node.GetCondition());
+ if (!cond_or_err)
+ return cond_or_err;
+ lldb::ValueObjectSP condition = *cond_or_err;
+
+ CompilerType cond_type = condition->GetCompilerType();
+ if (!cond_type.IsContextuallyConvertibleToBool()) {
+ std::string errMsg = llvm::formatv(
+ "value of type {0} is not contextually convertible to 'bool'",
+ cond_type.TypeDescription());
+ return llvm::make_error<DILDiagnosticError>(m_expr, errMsg,
+ node.GetLocation());
+ }
+ // Note: Unlike C++, DIL evaluates only the operand chosen by the condition,
----------------
kuilpd wrote:
> Thank you @kuilpd for the work that you are doing on DIL. I have been attempting to find the time to contribute for several months, but have not been able to get things at `$DAYJOB` under control. I hope that my minor amount of feedback on this PR makes your life a little easier. Thank you, again, for your great work on DIL!
No problem :) We already have plans and WIP implementation of further DIL features, so code review on PRs would be welcome.
> What you state about evaluation of only one of the conditional expression "arms" in DIL is true in C++, too: ["Only one of the second and third expressions is evaluated."](https://eel.is/c++draft/expr.cond#1.sentence-4). It seems like the real differentiator in the semantics is the fact that the types of the expressions in the arms is not checked in DIL but is checked in C++?
Yes, the only difference compared to C++ is that it doesn't check the types of the "arms". I've been told in another PR that comparing to C++ can make it confusing, so I'll remove it here as well.
https://github.com/llvm/llvm-project/pull/211344
More information about the lldb-commits
mailing list