This is a proposed fix for the crash of PR46865.
Details
Diff Detail
Event Timeline
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
3098 | This looks like a more appropriate assertion-check to me. But it's out of my area of experience, so I don't feel qualified to give an authoritative "LGTM". |
I think the assertion is correct: if we reach this point, then we have a DeclRefExpr that is not value-dependent and refers to a declaration whose initializer is value-dependent. That should never happen if the variable's type satisfies the requirements for use in a constant expression, which is what mightBeUsableInConstantExpressions checks.
The bug here appears to be that the dependency bits on a DeclRefExpr are computed too early when it refers to a templated variable -- before we instantiate the initializer -- and don't get "fixed" later when the initializer is instantiated. DoMarkVarDeclReferenced would be the right place to handle this -- after we trigger instantiation of the initializer, we should recompute the dependence bits on the DeclRefExpr, because they can depend on the initializer.
This looks like a more appropriate assertion-check to me. But it's out of my area of experience, so I don't feel qualified to give an authoritative "LGTM".