File tree 2 files changed +36
-4
lines changed
clang/include/clang/Analysis/Analyses 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change
1
+ // RUN: %check_clang_tidy -std=c++14-or-later %s performance-unnecessary-value-param %t
2
+
3
+ // The test case used to crash clang-tidy.
4
+ // https://github.com/llvm/llvm-project/issues/108963
5
+
6
+ struct A
7
+ {
8
+ template <typename T> A (T&&) {}
9
+ };
10
+
11
+ struct B
12
+ {
13
+ ~B ();
14
+ };
15
+
16
+ struct C
17
+ {
18
+ A a;
19
+ C (B, int i) : a(i) {}
20
+ // CHECK-MESSAGES: [[@LINE-1]]:6: warning: the parameter #1 is copied for each invocation but only used as a const reference; consider making it a const reference
21
+ };
22
+
23
+ C c (B(), 0);
Original file line number Diff line number Diff line change @@ -118,10 +118,19 @@ class FunctionParmMutationAnalyzer {
118
118
static FunctionParmMutationAnalyzer *
119
119
getFunctionParmMutationAnalyzer (const FunctionDecl &Func, ASTContext &Context,
120
120
ExprMutationAnalyzer::Memoized &Memorized) {
121
- auto [it, Inserted] = Memorized.FuncParmAnalyzer .try_emplace (&Func);
122
- if (Inserted)
123
- it->second = std::unique_ptr<FunctionParmMutationAnalyzer>(
124
- new FunctionParmMutationAnalyzer (Func, Context, Memorized));
121
+ auto it = Memorized.FuncParmAnalyzer .find (&Func);
122
+ if (it == Memorized.FuncParmAnalyzer .end ()) {
123
+ // Creating a new instance of FunctionParmMutationAnalyzer below may add
124
+ // additional elements to FuncParmAnalyzer. If we did try_emplace before
125
+ // creating a new instance, the returned iterator of try_emplace could be
126
+ // invalidated.
127
+ it =
128
+ Memorized.FuncParmAnalyzer
129
+ .try_emplace (&Func, std::unique_ptr<FunctionParmMutationAnalyzer>(
130
+ new FunctionParmMutationAnalyzer (
131
+ Func, Context, Memorized)))
132
+ .first ;
133
+ }
125
134
return it->getSecond ().get ();
126
135
}
127
136
You can’t perform that action at this time.
0 commit comments