================
@@ -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}}
+  }
+};
+WithField<int> with_field; // escape-note {{in instantiation of member 
function}} \
+                           // escape-note {{in instantiation of template 
class}}
----------------
NeKon69 wrote:

I have another idea for a test:
```cpp
template <class T>
struct S {
    constexpr auto get() const { return 0; }
    using R = decltype(&S::get);
};

S<int> s;
```
Pretty much the same thing but without an attribute.

https://github.com/llvm/llvm-project/pull/237022
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to