[clang] [libclang] Fix evaluation of parenthesized string initializers (PR #243317)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 25 13:58:49 PST 2026
================
@@ -4748,7 +4748,7 @@ static const ExprEvalResult *evaluateExpr(Expr *expr, CXCursor C) {
if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
const auto *I = cast<ImplicitCastExpr>(expr);
- auto *subExpr = I->getSubExprAsWritten();
+ auto *subExpr = I->getSubExprAsWritten()->IgnoreParens();
----------------
Endilll wrote:
N3886 6.3.3.3 p3:
> A _null pointer constant_ is an expression that, after generic replacement and removal of all surrounding
balanced parentheses, is an integer constant expression with the value 0 or such an expression cast
to type `void *`, or the predefined constant `nullptr`. If a null pointer constant or a value of the type
`nullptr_t` (which is necessarily the value `nullptr`) is converted to a pointer type, the resulting
pointer, called a _null pointer_, is guaranteed to compare unequal to a pointer to any object or function.
I don't think I want to get `CXEval_Int` with value 0 for a null pointer constant. I'd expect something spelled `nullptr` or `nullptr_t` instead, but I can be persuaded otherwise.
---
Stepping back, why are we even doing this special handling? Is it not possible to get the string literal out of `Expr::EvalResult`? If that is the case, why do we even bother calling `EvaluateAsRValue`?
https://github.com/llvm/llvm-project/pull/243317
More information about the cfe-commits
mailing list