[clang] [libclang] Fix evaluation of parenthesized string initializers (PR #243317)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 25 06:00:00 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();
----------------
AaronBallman wrote:
Good call on this changing behavior, that's definitely worth thinking about more.
In this case, it could be argued that it fixes a bug. There's no reason I can think of that we should not be able to evaluate that declaration. If we evaluate the initializer expression itself, we'll get `CXEval_Int` with a value of `0`:
```
F:\source\llvm-project>llvm\out\build\x64-Debug\bin\c-index-test.exe -evaluate-cursor-at="C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.c":1:1 "C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.c" -std=c23
1:6 VarDecl=p:1:6 (Definition) Extent=[1:1 - 1:11] Spelling=p ([1:6 - 1:7])Not Evaluatable
F:\source\llvm-project>llvm\out\build\x64-Debug\bin\c-index-test.exe -evaluate-cursor-at="C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.c":1:10 "C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.c" -std=c23
1:10 IntegerLiteral= Extent=[1:10 - 1:11]Kind: Int, Value: 0
```
CC @Endilll for more opinions
https://github.com/llvm/llvm-project/pull/243317
More information about the cfe-commits
mailing list