[PATCH] D151033: [clang][AST] TextNodeDumper should not evaluate the initializer of constexpr variable template definition

Takuya Shimizu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 21 04:40:42 PDT 2023


hazohelet added a comment.

In D151033#4359121 <https://reviews.llvm.org/D151033#4359121>, @tbaeder wrote:

> Can you briefly explain why the `FieldDecl` we see is null in that case?

Consider `template<typename T> constexpr T foo{};`

`evaluateValue` here leads to a call of `EvaluateAsInitializer`. It calls `CheckConstantExpression`, which leads to the call of `CheckEvaluationResult` with null  `FieldDecl`.
The `APValue`-typed `Value` argument passed to `CheckConstantExpression` should `hasValue` bacause otherwise it would cause assertion failure we saw before.
This `Value` object is calculated at `Evaluate` function called from `EvaluateAsInitializer`.
The evaluated `Expr` object is `InitListExpr` that has type `void`, so the branch for `void`-typed expression(https://github.com/llvm/llvm-project/blob/8b1727f8d9104df5ced4bdfdc065dea85ff84baf/clang/lib/AST/ExprConstant.cpp#L15041-L15046) is fired.
In this branch, the `Result` argument is left untouched, which leads to `CheckEvaluationResult` receiving `Value` object whose `hasValue` evaluates to `false`.

BTW, I noticed that when the type of the declaration is NOT a dependent type (e.g. `template <typename T> constexpr int foo{42}` ), we need to evaluate the initializer and dump the value. I'll update the patch and retitle it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151033/new/

https://reviews.llvm.org/D151033



More information about the cfe-commits mailing list