summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp')
-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);
+}