From 09d1f6e6b74c9330d80c0346a271a43efbe0384d Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Tue, 30 Mar 2021 10:45:04 +0200 Subject: [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 --- clang/unittests/Frontend/CompilerInvocationTest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp') 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. -- cgit v1.1