summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /build/clang-plugin/tests/TestRefCountedCopyConstructor.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
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);
+}