diff options
| author | George Burgess IV <gbiv@google.com> | 2020-03-09 21:06:54 -0700 |
|---|---|---|
| committer | George Burgess IV <gbiv@google.com> | 2020-03-09 21:11:05 -0700 |
| commit | a901c231ced74501805acbd09fc172e29dbaf3d0 (patch) | |
| tree | ecd26508f0096c46170735f377611fdd983f4340 | |
| parent | ae17ffdcf3da3c6743bf8d75be626c02c4ed0414 (diff) | |
| download | platform_build_kati-a901c231ced74501805acbd09fc172e29dbaf3d0.tar.gz platform_build_kati-a901c231ced74501805acbd09fc172e29dbaf3d0.tar.bz2 platform_build_kati-a901c231ced74501805acbd09fc172e29dbaf3d0.zip | |
func: rewrite a loop to appease -Wunreachable-code-loop-increment
This warning catches loops that can only execute once. It's unhappy
about the following code:
```
build/kati/func.cc:286:3: error: loop will run at most once (loop
increment never executed) [-Werror,-Wunreachable-code-loop-increment]
for (StringPiece tok : WordScanner(text)) {
^~~
```
Since that behavior seems intended here, just tweak the code to silence
the warning.
b/150166387
Test: TreeHugger passed at
https://android-review.googlesource.com/c/platform/build/kati/+/1252837
| -rw-r--r-- | func.cc | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -283,9 +283,10 @@ void WordsFunc(const vector<Value*>& args, Evaluator* ev, string* s) { void FirstwordFunc(const vector<Value*>& args, Evaluator* ev, string* s) { const string&& text = args[0]->Eval(ev); - for (StringPiece tok : WordScanner(text)) { - AppendString(tok, s); - return; + WordScanner ws(text); + auto begin = ws.begin(); + if (begin != ws.end()) { + AppendString(*begin, s); } } |
