Skip to content

Commit

Permalink
Use const reference for loop variables.
Browse files Browse the repository at this point in the history
* addresses the compiler warnings

```
composer/key_parser_test.cc:81:19: warning: loop variable '<structured bindings>' creates a copy from type 'const std::pair<std::basic_string_view<char>, unsigned int>' [-Wrange-loop-construct]
   81 |   for (const auto [name, modifiers] : kTestData) {
      |                   ^~~~~~~~~~~~~~~~~
composer/key_parser_test.cc:81:19: note: use reference type to prevent copying
   81 |   for (const auto [name, modifiers] : kTestData) {
      |                   ^~~~~~~~~~~~~~~~~
      |                   &
composer/key_parser_test.cc: In member function 'virtual void mozc::{anonymous}::KeyParserTest_SpecialKeys_Test::TestBody()':
composer/key_parser_test.cc:181:19: warning: loop variable '<structured bindings>' creates a copy from type 'const std::pair<std::basic_string_view<char>, mozc::commands::KeyEvent_SpecialKey>' [-Wrange-loop-construct]
  181 |   for (const auto [name, modifiers] : kTestData) {
      |                   ^~~~~~~~~~~~~~~~~
composer/key_parser_test.cc:181:19: note: use reference type to prevent copying
  181 |   for (const auto [name, modifiers] : kTestData) {
      |                   ^~~~~~~~~~~~~~~~~
      |                   &
```

#codehealth

PiperOrigin-RevId: 603603821
  • Loading branch information
hiroyuki-komatsu committed Feb 2, 2024
1 parent bbef260 commit 1ce8fe9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/composer/key_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST(KeyParserTest, ModifierKeys) {
{"SHIFT", KeyEvent::SHIFT},
};

for (const auto [name, modifiers] : kTestData) {
for (const auto& [name, modifiers] : kTestData) {
SCOPED_TRACE(name);
KeyEvent key_event;
EXPECT_TRUE(KeyParser::ParseKey(name, &key_event));
Expand Down Expand Up @@ -178,7 +178,7 @@ TEST(KeyParserTest, SpecialKeys) {
{"on", KeyEvent::ON},
};

for (const auto [name, modifiers] : kTestData) {
for (const auto& [name, modifiers] : kTestData) {
SCOPED_TRACE(name);
KeyEvent key_event;
EXPECT_TRUE(KeyParser::ParseKey(name, &key_event));
Expand Down

0 comments on commit 1ce8fe9

Please sign in to comment.