serge-sans-paille / frozen

a header-only, constexpr alternative to gperf for C++14 users
Apache License 2.0
1.31k stars 104 forks source link

test_unordered_set.cpp failed to be built with gcc 12.2.0 #160

Closed sgn closed 1 year ago

sgn commented 1 year ago
FAILED: tests/CMakeFiles/frozen.tests.dir/test_unordered_set.cpp.o 
/usr/lib/ccache/bin/g++  -I/builddir/frozen-1.1.1/include -DNDEBUG -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2   -g -ffile-prefix-map=/builddir/frozen-1.1.1/build=. -std=gnu++20 -Wall -Wextra -Wpedantic -Werror -Wshadow -MD -MT tests/CMakeFiles/frozen.tests.dir/test_unordered_set.cpp.o -MF tests/CMakeFiles/frozen.tests.dir/test_unordered_set.cpp.o.d -o tests/CMakeFiles/frozen.tests.dir/test_unordered_set.cpp.o -c /builddir/frozen-1.1.1/tests/test_unordered_set.cpp
../tests/test_unordered_set.cpp: In function 'void C_A_T_C_H_T_E_S_T_2()':
../tests/test_unordered_set.cpp:68:40:   in 'constexpr' expansion of 'ze_set.frozen::unordered_set<short unsigned int, 3>::count<int>(4)'
../include/frozen/unordered_set.h:113:17:   in 'constexpr' expansion of '((const frozen::unordered_set<short unsigned int, 3>*)this)->frozen::unordered_set<short unsigned int, 3>::count<int, frozen::elsa<short unsigned int>, std::equal_to<short unsigned int> >((* & key), (* &((const frozen::unordered_set<short unsigned int, 3>*)this)->frozen::unordered_set<short unsigned int, 3>::hash_function()), (* &((const frozen::unordered_set<short unsigned int, 3>*)this)->frozen::unordered_set<short unsigned int, 3>::key_eq()))'
../include/frozen/unordered_set.h:108:26:   in 'constexpr' expansion of '((const frozen::unordered_set<short unsigned int, 3>*)this)->frozen::unordered_set<short unsigned int, 3>::lookup<int, frozen::elsa<short unsigned int> >((* & key), (* & hash))'
../include/frozen/unordered_set.h:154:32:   in 'constexpr' expansion of '((const frozen::unordered_set<short unsigned int, 3>*)this)->frozen::unordered_set<short unsigned int, 3>::tables_.frozen::bits::pmh_tables<8, frozen::elsa<short unsigned int> >::lookup<int, frozen::elsa<short unsigned int> >((* & key), (* & hash))'
../tests/test_unordered_set.cpp:68:42:   in 'constexpr' expansion of 'frozen::bits::seed_or_index()'
../tests/test_unordered_set.cpp:68:42: error: modification of 'ze_set' is not a constant expression
   68 |   constexpr auto nocount = ze_set.count(4);
      |                                          ^

I have no clue why it run into this failure!

sgn commented 1 year ago

With this change, everything is fine.

--- a/tests/test_unordered_set.cpp
+++ b/tests/test_unordered_set.cpp
@@ -65,8 +65,8 @@ TEST_CASE("tripleton str frozen unordere
   constexpr auto max_size = ze_set.max_size();
   REQUIRE(max_size == 3);

-  constexpr auto nocount = ze_set.count(4);
+  auto nocount = ze_set.count(4);
   REQUIRE(nocount == 0);

   constexpr auto count = ze_set.count(1);
   REQUIRE(count == 1);

In my opinion, count doesn't modify ze_set in anyway :|

serge-sans-paille commented 1 year ago

Yeah, it doesn't make sense to me either... and the compile trace doesn't help either. Do you have the same issue with 12.3 and later?

serge-sans-paille commented 1 year ago

I've added extra CI in #162 and it seems to work with gcc 12.3: https://github.com/serge-sans-paille/frozen/actions/runs/5995811497/job/16259393963?pr=162

heirecka commented 1 year ago

It's actually a gcc a bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 12.3.0 upstream still is affected, but I suppose Ubuntu cherry-picks the patch mentioned in the bug report.