[PATCH] D100473: [clang] Implement CompilerInvocation copy assignment
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 19 02:12:38 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26bbb8700bb0: [clang] Implement CompilerInvocation copy assignment (authored by jansvoboda11).
Changed prior to commit:
https://reviews.llvm.org/D100473?vs=337422&id=338449#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100473/new/
https://reviews.llvm.org/D100473
Files:
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp
Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===================================================================
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -97,7 +97,7 @@
ASSERT_THAT(Array, ContainsN(StrEq("x"), 2));
}
-// Copy constructor performs a deep copy of reference-counted pointers.
+// Copy constructor/assignment perform deep copy of reference-counted pointers.
TEST(CompilerInvocationTest, DeepCopyConstructor) {
CompilerInvocation A;
@@ -109,6 +109,17 @@
ASSERT_EQ(A.getAnalyzerOpts()->Config["Key"], "Old");
}
+TEST(CompilerInvocationTest, DeepCopyAssignment) {
+ CompilerInvocation A;
+ A.getAnalyzerOpts()->Config["Key"] = "Old";
+
+ CompilerInvocation B;
+ 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.
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -125,6 +125,23 @@
PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())),
AnalyzerOpts(new AnalyzerOptions(*X.getAnalyzerOpts())) {}
+CompilerInvocationRefBase::CompilerInvocationRefBase(
+ CompilerInvocationRefBase &&X) = default;
+
+CompilerInvocationRefBase &
+CompilerInvocationRefBase::operator=(CompilerInvocationRefBase X) {
+ LangOpts.swap(X.LangOpts);
+ TargetOpts.swap(X.TargetOpts);
+ DiagnosticOpts.swap(X.DiagnosticOpts);
+ HeaderSearchOpts.swap(X.HeaderSearchOpts);
+ PreprocessorOpts.swap(X.PreprocessorOpts);
+ AnalyzerOpts.swap(X.AnalyzerOpts);
+ return *this;
+}
+
+CompilerInvocationRefBase &
+CompilerInvocationRefBase::operator=(CompilerInvocationRefBase &&X) = default;
+
CompilerInvocationRefBase::~CompilerInvocationRefBase() = default;
//===----------------------------------------------------------------------===//
Index: clang/include/clang/Frontend/CompilerInvocation.h
===================================================================
--- clang/include/clang/Frontend/CompilerInvocation.h
+++ clang/include/clang/Frontend/CompilerInvocation.h
@@ -91,8 +91,9 @@
CompilerInvocationRefBase();
CompilerInvocationRefBase(const CompilerInvocationRefBase &X);
- CompilerInvocationRefBase &
- operator=(const CompilerInvocationRefBase &) = delete;
+ CompilerInvocationRefBase(CompilerInvocationRefBase &&X);
+ CompilerInvocationRefBase &operator=(CompilerInvocationRefBase X);
+ CompilerInvocationRefBase &operator=(CompilerInvocationRefBase &&X);
~CompilerInvocationRefBase();
LangOptions *getLangOpts() { return LangOpts.get(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100473.338449.patch
Type: text/x-patch
Size: 2863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210419/147080ec/attachment-0001.bin>
More information about the cfe-commits
mailing list