summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp b/build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
new file mode 100644
index 0000000000..d3bd73084c
--- /dev/null
+++ b/build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
@@ -0,0 +1,25 @@
+// Implicit copy construct which is unused
+class RC1 {
+ void AddRef();
+ void Release();
+ int mRefCnt;
+};
+
+// Explicit copy constructor which is used
+class RC2 {
+public:
+ RC2();
+ RC2(const RC2&);
+private:
+ void AddRef();
+ void Release();
+ int mRefCnt;
+};
+
+void f() {
+ RC1* r1 = new RC1();
+ RC1* r1p = new RC1(*r1); // expected-error {{Invalid use of compiler-provided copy constructor on refcounted type}} expected-note {{The default copy constructor also copies the default mRefCnt property, leading to reference count imbalance issues. Please provide your own copy constructor which only copies the fields which need to be copied}}
+
+ RC2* r2 = new RC2();
+ RC2* r2p = new RC2(*r2);
+}