================
@@ -218,3 +239,138 @@ void caller() {
(void)n;
} // no-warning: No potential memory leak here, because that's been already
reported.
} // namespace symbol_reaper_lifetime
+
+
+// Minimal RAII class that properly deletes its pointer.
+class Bar {
+public:
+ explicit Bar(int *ptr) : ptr_(ptr) {}
+ ~Bar() {
+ if (ptr_) {
+ delete ptr_;
+ ptr_ = nullptr;
+ }
+ }
+
+ Bar(const Bar &) = delete;
+ Bar &operator=(const Bar &) = delete;
+
+ Bar(Bar &&other) noexcept : ptr_(other.ptr_) { other.ptr_ = nullptr; }
+ Bar &operator=(Bar &&other) noexcept {
+ if (this != &other) {
+ delete ptr_;
+ ptr_ = other.ptr_;
+ other.ptr_ = nullptr;
+ }
+ return *this;
+ }
+
+ int operator*() const { return *ptr_; }
+
+private:
+ int *ptr_;
+};
+
+// Factory returning a prvalue Bar that owns a freshly allocated int.
+static Bar make_bar(int v) { return Bar(new int(v)); }
+
+struct Foo {
+ Bar a;
+ Bar b;
+};
+
+struct FooWithConstructor {
+ Bar a;
+ Bar b;
+ FooWithConstructor(Bar &&original_a, Bar &&original_b)
+ : a(nstd::move(original_a)), b(nstd::move(original_b)) {}
+};
+
+//===----------------------------------------------------------------------===//
+// No-false-positive regression tests: these must be silent
+//===----------------------------------------------------------------------===//
+
+namespace prvalue_aggregate_transfer {
+
+void ok_aggregate_from_factory() {
+ Foo foo = {make_bar(1), make_bar(2)}; // expected-no-diagnostics
----------------
NagyDonat wrote:
In our test framework `// expected-no-diagnostics` would imply that there are
no diagnostics _anywhere in the test file_, which is obviously not the case
here.
If you want to verify that some code doesn't produce warnings, you don't need
to add any magic comment: warnings automatically imply failure of the test
unless they are matched by an `// expected-warning` comment (in which case
_not_ seeing the warning implies failure).
Some tests _do_ add comments like `// no-warning` or `// no-crash` to mark
significant lines (e.g. lines that would trigger a bug under earlier versions),
but these comments are only for the human readers: they don't have any special
meaning for our test system.
https://github.com/llvm/llvm-project/pull/155131
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits