Commit 7b7cc4e6 authored by Joe Loser's avatar Joe Loser Committed by Facebook Github Bot

Fix -Wstring-plus-int in FixedStringTest.cpp (#1148)

Summary:
- Clang 8 warns about appending integers to a string using `operator+`
  without a cast.

```
../folly/test/FixedStringTest.cpp:353:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
  a.append("X world!" + 2u, 5u);
           ~~~~~~~~~~~^~~~
../folly/test/FixedStringTest.cpp:353:23: note: use array indexing to silence this warning
  a.append("X world!" + 2u, 5u);
                      ^
           &          [   ]
../folly/test/FixedStringTest.cpp:354:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
  a.append("X world!" + 7u);
           ~~~~~~~~~~~^~~~
../folly/test/FixedStringTest.cpp:354:23: note: use array indexing to silence this warning
  a.append("X world!" + 7u);
                      ^
           &          [   ]
../folly/test/FixedStringTest.cpp:365:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
  a.append("X world!" + 2u, 5u);
           ~~~~~~~~~~~^~~~
../folly/test/FixedStringTest.cpp:365:23: note: use array indexing to silence this warning
  a.append("X world!" + 2u, 5u);
                      ^
           &          [   ]
../folly/test/FixedStringTest.cpp:366:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
  a.append("X world!" + 7u);
           ~~~~~~~~~~~^~~~
../folly/test/FixedStringTest.cpp:366:23: note: use array indexing to silence this warning
  a.append("X world!" + 7u);
                      ^
           &          [   ]
```

- Fix this warning by creating a local char[] and using that to append
  to the fixed string
Pull Request resolved: https://github.com/facebook/folly/pull/1148

Reviewed By: ericniebler

Differential Revision: D15618465

Pulled By: yfeldblum

fbshipit-source-id: 7f72b3597f51d99665da85744aeb8805eb2e8f00
parent de733c9a
...@@ -350,8 +350,9 @@ TEST(FixedStringAssignTest, RuntimeAppendString) { ...@@ -350,8 +350,9 @@ TEST(FixedStringAssignTest, RuntimeAppendString) {
constexpr folly::FixedString<20> constexpr_append_literal_test() { constexpr folly::FixedString<20> constexpr_append_literal_test() {
folly::FixedString<20> a{"hello"}; folly::FixedString<20> a{"hello"};
a.append(1u, ' '); a.append(1u, ' ');
a.append("X world!" + 2u, 5u); constexpr char s[] = "X world!";
a.append("X world!" + 7u); a.append(&s[2u], 5u);
a.append(&s[7u]);
return a; return a;
} }
...@@ -362,8 +363,9 @@ TEST(FixedStringAssignTest, ConstexprAppendLiteral) { ...@@ -362,8 +363,9 @@ TEST(FixedStringAssignTest, ConstexprAppendLiteral) {
TEST(FixedStringAssignTest, RuntimeAppendLiteral) { TEST(FixedStringAssignTest, RuntimeAppendLiteral) {
folly::FixedString<20> a{"hello"}; folly::FixedString<20> a{"hello"};
a.append(1u, ' '); a.append(1u, ' ');
a.append("X world!" + 2u, 5u); constexpr char s[] = "X world!";
a.append("X world!" + 7u); a.append(&s[2u], 5u);
a.append(&s[7u]);
EXPECT_STREQ("hello world!", a.c_str()); EXPECT_STREQ("hello world!", a.c_str());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment