[clang] [Clang] [FlowSensitive] handle curiously recurring template pattern (PR #234916)
Jan Voung via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 4 07:54:26 PST 2026
================
@@ -471,7 +447,22 @@ BoolValue *getHasValue(Environment &Env, RecordStorageLocation *OptionalLoc) {
}
QualType valueTypeFromOptionalDecl(const CXXRecordDecl &RD) {
+
auto &CTSD = cast<ClassTemplateSpecializationDecl>(RD);
+
+ // handle curiously recurring template pattern
----------------
jvoung wrote:
Ok, thanks for the context with crubit's rs::Option. That does have the `value_type` in `OptionBase<Derived, T>` though, so might hit the inheriting class case. That also has a specialization for `Option<T&>` where `value_type` is adjusted from `T&` to `T` (https://github.com/google/crubit/blob/d7657d730310102933c7030309398eea8e44dac6/support/rs_std/option.h#L330).
I think it depends whether the checker recognizes OptionBase or Option as the "optional class", or what is the `RD` being passed here.
- If RD == OptionBase -- seems okay, it will find the `value_type` there
- If RD == Option, then it won't find `value_type`... but it also wouldn't have the CRTP problem?
- For the `T&` specialization, it might get the wrong value_type since it doesn't search the bases and just guesses from the template param `T&`.
It's a bit hard to tell without testing on the real integration of `analyze_as_class` (or the final design), if checking through the inheriting classes is needed.
However, perhaps the C++26 std::optional specialization for `T&` would have the same problem, and that perhaps could be tested now with an updated mock header that is closer to the real C++26 header?
https://github.com/llvm/llvm-project/pull/234916
More information about the cfe-commits
mailing list