Skip to content

Commit 5ea8b5a

Browse files
committed
refactor(move): remove lifetime-container-move to simplify usage
1 parent c15489a commit 5ea8b5a

5 files changed

Lines changed: 16 additions & 99 deletions

File tree

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,6 @@ void bar(std::vector<std::unique_ptr<int>>& cont, std::unique_ptr<int>& p)
445445
}
446446
```
447447
448-
You can use `-Wlifetime-container-move` to enable check for it. But it's always better to introduce a helper function to state your intent:
449-
450-
```cpp
451-
// pset(container) = {*container}
452-
move_each(std::move(container), [](auto&& elem){
453-
// use elem
454-
});
455-
// pset(container) = {invalid}
456-
assert(container.empty());
457-
```
458-
459448
# Difference from the original implementation
460449
## Output variable
461450
### Return check

include/cppsafe/Options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct CppsafeOptions {
1010
bool LifetimeDisabled = false;
1111
bool LifetimeGlobal = false;
1212
bool LifetimeOutput = false;
13-
bool LifetimeContainerMove = false;
1413
};
1514

1615
}

integration_test/feature/move_container.cpp

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/lifetime/LifetimePsetBuilder.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,12 +841,23 @@ class PSetsBuilder final : public ConstStmtVisitor<PSetsBuilder, void>, public P
841841
}
842842

843843
if (PS.containsParent(V)) {
844+
// WORKAROUND
844845
// when move var with pset {*container}, only invalidate the var itself,
845-
// containers and iterators are not invalidated
846-
if (!Reporter.getOptions().LifetimeContainerMove) {
847-
if (V.isDeref() && isIteratorOrContainer(Var.getType())) {
848-
continue;
849-
}
846+
// containers and iterators are not invalidated.
847+
// <code>
848+
// void foo(std::vector<std::unique_ptr<int>>& cont, std::unique_ptr<int>& p)
849+
//{
850+
// for (auto& x : cont) {
851+
// p = std::move(x);
852+
//}
853+
854+
// for (auto& x: cont) {
855+
// use(x);
856+
//}
857+
//}
858+
//</code>
859+
if (V.isDeref() && isIteratorOrContainer(Var.getType())) {
860+
continue;
850861
}
851862
setPSet(PSet::singleton(Var), PSet::invalid(Reason), Reason.getRange());
852863
}

src/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ static const cl::opt<bool> WarnLifetimeDisabled("Wlifetime-disabled",
6262
static const cl::opt<bool> WarnLifetimeOutput("Wlifetime-output",
6363
desc("Enforce output parameter validity check in all paths"), cl::init(false), cl::cat(CppSafeCategory));
6464

65-
static const cl::opt<bool> WarnLifetimeContainerMove("Wlifetime-container-move",
66-
desc("Enable strict check on element move of containers"), cl::init(false), cl::cat(CppSafeCategory));
67-
6865
struct DetectSystemIncludesError : public std::runtime_error {
6966
using std::runtime_error::runtime_error;
7067
};
@@ -132,7 +129,6 @@ class LifetimeFrontendAction : public clang::ASTFrontendAction {
132129
.LifetimeDisabled = WarnLifetimeDisabled,
133130
.LifetimeGlobal = WarnLifetimeGlobal,
134131
.LifetimeOutput = WarnLifetimeOutput,
135-
.LifetimeContainerMove = WarnLifetimeContainerMove,
136132
};
137133

138134
return std::make_unique<AstConsumer>(Options);

0 commit comments

Comments
 (0)