Files
codeql/cpp/ql/test/query-tests/Best Practices/Hiding/DeclarationHidesVariable/hiding.cpp
Jeroen Ketema 46821fe136 Update C++ variable hiding test
Structured bindings are now handled better, so the false negative
related to structured bindings is now a true positive.
2022-02-10 10:58:32 +01:00

42 lines
606 B
C++

// semmle-extractor-options: -std=c++17
void f(void) {
if (1) {
int i;
for(int i = 1; i < 10; i++) { // BAD
;
}
}
}
namespace foo {
namespace bar {
void f2(int i) {
int k;
try {
for (i = 0; i < 3; i++) {
int k; // BAD
}
}
catch (int e) {
}
}
}
}
void nestedRangeBasedFor() {
int xs[4], ys[4];
for (auto x : xs)
for (auto y : ys) // GOOD
x = y = 0;
}
void structuredBinding() {
int xs[1] = {1};
auto [x] = xs;
{
auto [x] = xs; // BAD
auto [y] = xs; // GOOD
}
}