================
@@ -701,3 +701,45 @@ Ref<RefCountable>
[[clang::annotate_type("webkit.nodelete")]] returnTypedefPrval
} // namespace returned_prvalue_typedef
+namespace create_with_default_constructor {
+
+ struct ObjectWithDefaultConstructorWithoutMemberVariables {
+ void ref() const;
+ void deref() const;
+
+ static auto [[clang::annotate_type("webkit.nodelete")]] create() {
+ return adoptRef(*new
ObjectWithDefaultConstructorWithoutMemberVariables());
+ }
+ };
+
+ struct ObjectWithDefaultConstructorWithPODMemberVariables {
+ void ref() const;
+ void deref() const;
+
+ static auto [[clang::annotate_type("webkit.nodelete")]] create() {
+ return adoptRef(*new
ObjectWithDefaultConstructorWithPODMemberVariables());
+ }
+
+ private:
+ int value { 0 };
+ RefCountable* ptr { nullptr };
+ };
+
+ struct ObjectWithOpaqueCtor {
+ ObjectWithOpaqueCtor();
+ };
+
+ struct ObjectWithDefaultConstructorWithOpaqueCtorMemberVariables {
+ void ref() const;
+ void deref() const;
+
+ static auto [[clang::annotate_type("webkit.nodelete")]] create() {
+ return adoptRef(*new
ObjectWithDefaultConstructorWithOpaqueCtorMemberVariables());
+ // expected-warning@-1{{A function 'create' has
[[clang::annotate_type("webkit.nodelete")]] but it contains code that could
destruct an object}}
+ }
+
+ private:
+ ObjectWithOpaqueCtor obj;
+ };
+
+} // namespace create_with_default_constructor
----------------
rniwa wrote:
Because adding an empty constructor makes the warning go away. My initial
thinking was same as you that we're failing to detect that a destructor won't
be called here but that's not what's happening.
The following code will generate a warning:
```
struct Foo {
void ref() const;
void deref() const;
static auto [[clang::annotate_type("webkit.nodelete")]] create() {
return adoptRef(*new Foo());
}
};
```
While the following code does not:
```
struct Bar {
Bar() { }
void ref() const;
void deref() const;
static auto [[clang::annotate_type("webkit.nodelete")]] create() {
return adoptRef(*new Bar());
}
};
```
As a matter of fact, I added logging in various places and it showed me that
we're returning `false` due to the lack of the function body.
https://github.com/llvm/llvm-project/pull/201544
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits