aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Frontend/CompilerInvocationTest.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2021-03-30 10:45:04 +0200
committerJan Svoboda <jan_svoboda@apple.com>2021-04-14 09:13:35 +0200
commit09d1f6e6b74c9330d80c0346a271a43efbe0384d (patch)
tree601b28f10f8da1419feed3eee2c7aa71605a0a48 /clang/unittests/Frontend/CompilerInvocationTest.cpp
parent0acf4e500529447ba34b8d9152630c8535d17949 (diff)
downloadllvm-09d1f6e6b74c9330d80c0346a271a43efbe0384d.zip
llvm-09d1f6e6b74c9330d80c0346a271a43efbe0384d.tar.gz
llvm-09d1f6e6b74c9330d80c0346a271a43efbe0384d.tar.bz2
[clang] Fix copy constructor of CompilerInvocation
The `CompilerInvocationBase` class factors out members of `CompilerInvocation` that need special handling (initialization or copy constructor), so that `CompilerInvocation` can be implemented as a simple value object. Currently, the `AnalyzerOpts` member of `CompilerInvocation` violates that setup. This patch extracts the member to `CompilerInvocationBase` and handles it in the copy constructor the same way other it handles other members. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D99568
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r--clang/unittests/Frontend/CompilerInvocationTest.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 066d02b..5062a2e 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -97,6 +97,18 @@ TEST(ContainsN, Two) {
ASSERT_THAT(Array, ContainsN(StrEq("x"), 2));
}
+// Copy constructor performs a deep copy of reference-counted pointers.
+
+TEST(CompilerInvocationTest, DeepCopyConstructor) {
+ CompilerInvocation A;
+ A.getAnalyzerOpts()->Config["Key"] = "Old";
+
+ CompilerInvocation B(A);
+ B.getAnalyzerOpts()->Config["Key"] = "New";
+
+ ASSERT_EQ(A.getAnalyzerOpts()->Config["Key"], "Old");
+}
+
// Boolean option with a keypath that defaults to true.
// The only flag with a negative spelling can set the keypath to false.