Skip to content

Commit c98accb

Browse files
committed
add test
1 parent 2abd7da commit c98accb

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

test/testunusedvar.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ class TestUnusedVar : public TestFixture {
259259
TEST_CASE(escapeAlias); // #9150
260260
TEST_CASE(volatileData); // #9280
261261
TEST_CASE(globalData);
262+
263+
TEST_CASE(structuredBinding); // #13269
262264
}
263265

264266
struct FunctionVariableUsageOptions
@@ -7197,6 +7199,42 @@ class TestUnusedVar : public TestFixture {
71977199
"}");
71987200
ASSERT_EQUALS("", errout_str());
71997201
}
7202+
7203+
void structuredBinding() { // #13269
7204+
functionVariableUsage("int main()\n"
7205+
"{\n"
7206+
" auto [a, b] = std::make_pair(42, 0.42);\n"
7207+
"}\n");
7208+
ASSERT_EQUALS("[test.cpp:3:17]: (style) Variable 'a' is assigned a value that is never used. [unreadVariable]\n"
7209+
"[test.cpp:3:17]: (style) Variable 'b' is assigned a value that is never used. [unreadVariable]\n", errout_str());
7210+
7211+
functionVariableUsage("int main()\n"
7212+
"{\n"
7213+
" auto [a, b] = std::make_pair(42, 0.42);\n"
7214+
" (void) a;\n"
7215+
"}\n");
7216+
ASSERT_EQUALS("", errout_str());
7217+
7218+
functionVariableUsage("int main()\n"
7219+
"{\n"
7220+
" auto [a, b] = std::make_pair(42, 0.42);\n"
7221+
" (void) b;\n"
7222+
"}\n");
7223+
ASSERT_EQUALS("", errout_str());
7224+
7225+
functionVariableUsage("int main()\n"
7226+
"{\n"
7227+
" auto [a, b, c] = std::make_pair(42, 0.42);\n"
7228+
" (void) b;\n"
7229+
"}\n");
7230+
ASSERT_EQUALS("", errout_str());
7231+
7232+
functionVariableUsage("int main()\n"
7233+
"{\n"
7234+
" [[maybe_unused]] auto [a2, b3] = std::make_pair(42, 0.42);\n"
7235+
"}\n");
7236+
ASSERT_EQUALS("", errout_str());
7237+
}
72007238
};
72017239

72027240
REGISTER_TEST(TestUnusedVar)

0 commit comments

Comments
 (0)