abseil / abseil/abseil-cpp

StrSplit return as std::set/absl::flat_hash_set triggers warning

未關閉
#1,233 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
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 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。