abseil / abseil/abseil-cpp

[Bug]: Constexpr expansion compilation error with GCC's UndefinedBehaviorSanitizer

未關閉
#1,634 14 則留言 18 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C++
星號
18.1k
分支
3.2k
平均合併
20 小時 36 分鐘
30 天內合併 PR
1

描述

### Describe the issue

When building abseil with GCC with `-fsanitize=undefined`, the following compilation error occurs:
```
/abseil/absl/container/internal/raw_hash_set.h:3364:56: in 'constexpr' expansion of 'absl::container_internal::hash_policy_traits, absl::CommandLineFlag*>, void>::get_hash_slot_fn()'
/abseil/absl/container/internal/hash_policy_traits.h:163:54: error: '(absl::container_internal::TypeErasedApplyToSlotFn > == 0)' is not a constant expression
163 | return Policy::template get_hash_slot_fn() == nullptr
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
make-4.3[4]: *** [absl/flags/CMakeFiles/flags_reflection.dir/build.make:66: absl/flags/CMakeFiles/flags_reflection.dir/reflection.cc.o] Error 1
```

This code producing the error has been introduced with commit 4c7e7c7d9.

The error does *not* occur when building with no sanitizer or when building with `-fsanitize=address` or `-fsanitize=thread`.

This seems to be a known GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962

### Steps to reproduce the problem

```
git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
mkdir build
cd build
cmake -DCMAKE_CXX_FLAGS="-fsanitize=undefined" ..
make
```
Isolated expression from the method where the error occurs (`absl::container_internal::hash_policy_traits::get_hash_slot_fn()`) with `-std=gnu++17 -fsanitize=undefined`: https://godbolt.org/z/8bEazf6e5

### What version of Abseil are you using?

7bd9ff910d489658da58251de1317eb3f790a2c6

### What operating system and version are you using?

Ubuntu 20.04.6 LTS

### What compiler and version are you using?

GCC 9.4.0
Also tested with GCC 13.2 on linked godbolt.

### What build system are you using?

cmake 3.16.3

### Additional context

_No response_

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

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

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