abseil-cpp
abseil-cpp copied to clipboard
Initialize `Allocation` to eliminate compile error
Class Allocation
is not initialized and I will get a compile error like this.
error: ‘worklist.absl::lts_20220623::InlinedVector<absl::lts_20220623::cord_internal::CordRep*, 2, std::allocator<absl::lts_20220623::cord_internal::CordRep*> >::storage_.absl::lts_20220623::inlined_vector_internal::Storage<absl::lts_20220623::cord_internal::CordRep*, 2, std::allocator<absl::lts_20220623::cord_internal::CordRep*> >::data_.absl::lts_20220623::inlined_vector_internal::Storage<absl::lts_20220623::cord_internal::CordRep*, 2, std::allocator<absl::lts_20220623::cord_internal::CordRep*> >::Data::allocated.absl::lts_20220623::inlined_vector_internal::Storage<absl::lts_20220623::cord_internal::CordRep*, 2, std::allocator<absl::lts_20220623::cord_internal::CordRep*> >::Allocated::allocated_capacity’ may be used uninitialized [-Werror=maybe-uninitialized]
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
- We need the CLA.
- I can't reproduce this problem. Can you provide reproduction instructions?
- We need the CLA.
- I can't reproduce this problem. Can you provide reproduction instructions?
- Done
- I compile it like this.
My directory tree is like this.
$ tree
.
|-- bld
|-- cmake
| `-- abseil.cmake
|-- CMakeLists.txt
`-- main.cpp
2 directories, 3 files
main.cpp
#include "absl/container/flat_hash_set.h"
int main(int argc, char** argv) {
absl::flat_hash_set<int> set;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.20.2)
project(test-abseil
VERSION 1.0
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "cxx version ${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -O3 -g -mavx2")
message(STATUS "cxx_flags ${CMAKE_CXX_FLAGS}")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include_directories(include)
# abseil
include(abseil)
add_executable(main main.cpp)
target_link_libraries(main absl::random_random absl::strings absl::time absl::flat_hash_map absl::synchronization)
cmake/abseil.cmake
include(FetchContent)
set(GTEST_GIT_TAG master)
set(GTEST_GIT_URL https://github.com/abseil/abseil-cpp.git)
FetchContent_Declare(
abseil
GIT_REPOSITORY ${GTEST_GIT_URL}
GIT_TAG ${GTEST_GIT_TAG}
)
FetchContent_MakeAvailable(abseil)
I compile it with cmd mkdir bld; cmake -S . -B bld && cmake --build bld
and I get error as follows.
In file included from /root/workspace/tmp/bld/_deps/abseil-src/absl/container/inlined_vector.h:53,
from /root/workspace/tmp/bld/_deps/abseil-src/absl/strings/cord.h:78,
from /root/workspace/tmp/bld/_deps/abseil-src/absl/strings/cord.cc:15:
In member function ‘absl::inlined_vector_internal::SizeType<A> absl::inlined_vector_internal::Storage<T, N, A>::GetAllocatedCapacity() const [with T = absl::cord_internal::CordRep*; long unsigned int N = 2; A = std::allocator<absl::cord_internal::CordRep*>]’,
inlined from ‘void absl::inlined_vector_internal::Storage<T, N, A>::DeallocateIfAllocated() [with T = absl::cord_internal::CordRep*; long unsigned int N = 2; A = std::allocator<absl::cord_internal::CordRep*>]’ at /root/workspace/tmp/bld/_deps/abseil-src/absl/container/internal/inlined_vector.h:452:35,
inlined from ‘absl::inlined_vector_internal::Storage<T, N, A>::~Storage() [with T = absl::cord_internal::CordRep*; long unsigned int N = 2; A = std::allocator<absl::cord_internal::CordRep*>]’ at /root/workspace/tmp/bld/_deps/abseil-src/absl/container/internal/inlined_vector.h:323:28,
inlined from ‘absl::InlinedVector<T, N, A>::~InlinedVector() [with T = absl::cord_internal::CordRep*; long unsigned int N = 2; A = std::allocator<absl::cord_internal::CordRep*>]’ at /root/workspace/tmp/bld/_deps/abseil-src/absl/container/inlined_vector.h:256:21,
inlined from ‘bool absl::VerifyNode(absl::cord_internal::CordRep*, absl::cord_internal::CordRep*, bool)’ at /root/workspace/tmp/bld/_deps/abseil-src/absl/strings/cord.cc:1308:1:
/root/workspace/tmp/bld/_deps/abseil-src/absl/container/internal/inlined_vector.h:360:28: error: ‘worklist.absl::InlinedVector<absl::cord_internal::CordRep*, 2, std::allocator<absl::cord_internal::CordRep*> >::storage_.absl::inlined_vector_internal::Storage<absl::cord_internal::CordRep*, 2, std::allocator<absl::cord_internal::CordRep*> >::data_.absl::inlined_vector_internal::Storage<absl::cord_internal::CordRep*, 2, std::allocator<absl::cord_internal::CordRep*> >::Data::allocated.absl::inlined_vector_internal::Storage<absl::cord_internal::CordRep*, 2, std::allocator<absl::cord_internal::CordRep*> >::Allocated::allocated_capacity’ may be used uninitialized [-Werror=maybe-uninitialized]
360 | return data_.allocated.allocated_capacity;
| ^~~~~~~~~~~~~~~~~~
/root/workspace/tmp/bld/_deps/abseil-src/absl/strings/cord.cc: In function ‘bool absl::VerifyNode(absl::cord_internal::CordRep*, absl::cord_internal::CordRep*, bool)’:
/root/workspace/tmp/bld/_deps/abseil-src/absl/strings/cord.cc:1274:36: note: ‘worklist’ declared here
1274 | absl::InlinedVector<CordRep*, 2> worklist;
| ^~~~~~~~
Exactly, the error is a warning. But I use -Werror
, so it failed to compile.
Reproduction instructions need to include the compiler version and operating system. Please provide this information.
-Werror
is unsupported. You should only compile your own code with -Werror
. We have a CMake option ABSL_USE_SYSTEM_INCLUDES
for this.
We should fix this though. Please let us know the exact version of the tools used.
Reproduction instructions need to include the compiler version and operating system. Please provide this information.
-Werror
is unsupported. You should only compile your own code with-Werror
. We have a CMake optionABSL_USE_SYSTEM_INCLUDES
for this.We should fix this though. Please let us know the exact version of the tools used.
cmake: 3.20.2 GCC: 11.2.1 Linux OS: CentOS Linux release 7.9.2009 (Core) LInux Kernel: Linux ost 5.10.104-linuxkit #1 SMP Thu Mar 17 17:08:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
-Werror is unsupported.
Maybe it is better to support Werror
, isn't it?
Maybe it is better to support
Werror
, isn't it?
Supporting -Werror
means we have to support whatever arbitrary set of warnings people decide to enable, even bad or buggy warnings. It's fine to compile your own code with -Werror
if you want, but don't force -Werror
on your dependencies. So no, we will never support -Werror
.
Maybe it is better to support
Werror
, isn't it?Supporting
-Werror
means we have to support whatever arbitrary set of warnings people decide to enable, even bad or buggy warnings. It's fine to compile your own code with-Werror
if you want, but don't force-Werror
on your dependencies. So no, we will never support-Werror
.
Get it
Any more questions to merge this code? @derekmauro