aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2020-03-09 21:06:54 -0700
committerGeorge Burgess IV <gbiv@google.com>2020-03-09 21:11:05 -0700
commita901c231ced74501805acbd09fc172e29dbaf3d0 (patch)
treeecd26508f0096c46170735f377611fdd983f4340
parentae17ffdcf3da3c6743bf8d75be626c02c4ed0414 (diff)
downloadplatform_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.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/func.cc b/func.cc
index 2713fbe..e38e0e7 100644
--- a/func.cc
+++ b/func.cc
@@ -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);
}
}