[clang] [LifetimeSafety] Fix crash on eagerly instantiated methods (PR #237022)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 30 06:45:03 PDT 2026


================
@@ -402,3 +402,20 @@ struct HasField {
   }
 };
 } // namespace LambdaCaptureReset
+
+// `used constexpr` methods are analyzed while their class is being defined.
+namespace GH236616 {
+template <class T> struct NoFields {
+  __attribute__((used)) constexpr int get() const { return 0; }
+};
+NoFields<int> no_fields;
+
+template <class T> struct WithField {
+  const int *p; // escape-note {{if field 'p' is owned by the class}}
+  __attribute__((used)) constexpr const int *get() const { // escape-warning {{depends on the object referenced by field 'p'}}
+    return p; // escape-note {{returned here}}
----------------
NeKon69 wrote:

nit: align the comments here

https://github.com/llvm/llvm-project/pull/237022


More information about the cfe-commits mailing list