StrSplit return as std::set/absl::flat_hash_set triggers warning
- 主要语言
- C++
- 星标
- 18.1k
- 派生
- 3.2k
- 平均合并
- 20 小时 36 分钟
- 30 天内合并 PR
- 1
描述
I'm currently using Abseil-app from the master branch. My code:
```c++
std::set controllers = absl::StrSplit(*content, ' '); // content: absl::StatusOr
```
Would trigger:
```shell
In file included from /home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/strings/str_split.h:48,
from /home/parallels/weiran-dev/rouster/src/main.cpp:11:
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h: In instantiation of ‘absl::strings_internal::SplitIterator& absl::strings_internal::SplitIterator::operator++() [with Splitter = absl::strings_internal::Splitter >]’:
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h:321:7: required from ‘Container absl::strings_internal::Splitter::ConvertToContainer::operator()(const absl::strings_internal::Splitter&) const [with Container = std::set >; ValueType = std::__cxx11::basic_string; bool is_map = false; Delimiter = absl::ByChar; Predicate = absl::AllowEmpty; StringType = std::basic_string_view]’
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h:288:65: required from ‘absl::strings_internal::Splitter::operator Container() const [with Container = std::set >; = void; Delimiter = absl::ByChar; Predicate = absl::AllowEmpty; StringType = std::basic_string_view]’
/home/parallels/weiran-dev/rouster/src/main.cpp:54:71: required from here
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h:135:42: warning: conversion to ‘std::basic_string_view::size_type’ {aka ‘long unsigned int’} from ‘long int’ may change the sign of the result [-Wsign-conversion]
135 | curr_ = text.substr(pos_, d.data() - (text.data() + pos_));
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
```
And `absl::flat_hash_set` will trigger additional warnings (besides the above warning):
```shell
In file included from /home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h:40,
from /home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/container/internal/inlined_vector.h:30,
from /home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/container/inlined_vector.h:53,
from /home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/status/status.h:57,
from /home/parallels/weiran-dev/rouster/src/linux/sys.h:1,
from /home/parallels/weiran-dev/rouster/src/container.hpp:12,
from /home/parallels/weiran-dev/rouster/src/main.cpp:6:
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/utility/utility.h: In instantiation of ‘T absl::exchange(T&, U&&) [with T = long unsigned int; U = int]’:
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h:1275:29: required from ‘absl::container_internal::raw_hash_set::raw_hash_set(absl::container_internal::raw_hash_set&&) [with Policy = absl::container_internal::FlatHashSetPolicy >; Hash = absl::container_internal::StringHash; Eq = absl::container_internal::StringEq; Alloc = std::allocator >]’
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/container/flat_hash_set.h:105:7: required from ‘Container absl::strings_internal::Splitter::ConvertToContainer::operator()(const absl::strings_internal::Splitter&) const [with Container = absl::flat_hash_set >; ValueType = std::basic_string_view; bool is_map = false; Delimiter = absl::ByChar; Predicate = absl::AllowEmpty; StringType = std::basic_string_view]’
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h:288:65: required from ‘absl::strings_internal::Splitter::operator Container() const [with Container = absl::flat_hash_set >; = void; Delimiter = absl::ByChar; Predicate = absl::AllowEmpty; StringType = std::basic_string_view]’
/home/parallels/weiran-dev/rouster/src/main.cpp:54:87: required from here
/home/parallels/weiran-dev/rouster/third_party/abseil-cpp/absl/utility/utility.h:316:7: warning: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]
316 | obj = absl::forward(new_value);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Seems like there exist some implicit conversions. Though these are not errors, can we have a fix for them?
贡献指南
评估
这个 Issue 还没有评估数据。