serge-sans-paille / frozen

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

Test compilation error #150

Closed amosnier closed 1 year ago

amosnier commented 1 year ago

Since this repository sounded promising, I clone it and tried running the tests, but unfortunately I get a compilation error with g++ 12.2 (commit 5666e8cd770fa1fc6afbc3c24a36aad418332e73):

$ make -C tests/ check
make: Entering directory 'frozen/tests'
g++ -O3 -Wall -std=c++14 -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_main.o test_main.cpp
g++ -O3 -Wall -std=c++14 -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_rand.o test_rand.cpp
g++ -O3 -Wall -std=c++14 -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_set.o test_set.cpp
g++ -O3 -Wall -std=c++14 -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_map.o test_map.cpp
g++ -O3 -Wall -std=c++14 -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_unordered_set.o test_unordered_set.cpp
test_unordered_set.cpp: In function ‘void C_A_T_C_H_T_E_S_T_15()’:
test_unordered_set.cpp:195:18: error: the type ‘const frozen::unordered_set<frozen::basic_string<char>, 3, frozen::elsa<void>, C_A_T_C_H_T_E_S_T_15()::<lambda(const frozen::string&, const auto:1&)> >’ of ‘constexpr’ variable ‘set’ is not literal
  195 |   constexpr auto set = frozen::make_unordered_set<frozen::string>(
      |                  ^~~
In file included from test_unordered_set.cpp:2:
../include/frozen/unordered_set.h:49:7: note: ‘frozen::unordered_set<frozen::basic_string<char>, 3, frozen::elsa<void>, C_A_T_C_H_T_E_S_T_15()::<lambda(const frozen::string&, const auto:1&)> >’ is not literal because:
   49 | class unordered_set {
      |       ^~~~~~~~~~~~~
../include/frozen/unordered_set.h:55:18: note:   non-static data member ‘frozen::unordered_set<frozen::basic_string<char>, 3, frozen::elsa<void>, C_A_T_C_H_T_E_S_T_15()::<lambda(const frozen::string&, const auto:1&)> >::equal_’ has non-literal type
   55 |   KeyEqual const equal_;
      |                  ^~~~~~
test_unordered_set.cpp:191:20: note: ‘C_A_T_C_H_T_E_S_T_15()::<lambda(const frozen::string&, const auto:1&)>’ is not literal because:
  191 |   const auto eq = [](const frozen::string& frozen, const auto& str) {
      |                    ^
cc1plus: note:   ‘C_A_T_C_H_T_E_S_T_15()::<lambda(const frozen::string&, const auto:1&)>’ is a closure type, which is only literal in C++17 and later
make: *** [<builtin>: test_unordered_set.o] Error 1
$ g++ --version
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0

Maybe it is easy to fix?

Thanks in advance,

Best regards,

Alain Mosnier

amosnier commented 1 year ago

In fact, if I arbitrarily switch on the highest C++ standard my compiler gives me access to, so-called c++2b in this case, the tests seem to run perfectly well:

$ make -j check
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_main.o test_main.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_rand.o test_rand.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_set.o test_set.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_map.o test_map.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_unordered_set.o test_unordered_set.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_str_set.o test_str_set.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_unordered_str_set.o test_unordered_str_set.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_unordered_map.o test_unordered_map.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_unordered_map_str.o test_unordered_map_str.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_str.o test_str.cpp
g++ -O3 -Wall -std=c++2b -march=native -Wextra -W -Werror -Wshadow -fPIC -I../include  -c -o test_algorithms.o test_algorithms.cpp
g++ test_main.o test_rand.o test_set.o test_map.o test_unordered_set.o test_str_set.o test_unordered_str_set.o test_unordered_map.o test_unordered_map_str.o test_str.o test_algorithms.o -o test_main
./test_main
===============================================================================
All tests passed (3727 assertions in 55 test cases)

It still feels weird that it would suddenly start to fail with C++14 if it did not earlier. Did g++ suddenly realize that they were letting through too advanced code for C++14? Anyway, please do whatever you feel is applicable with this issue. At least, it should not be a problem for me, and I will now test this library in my current pet project. Thanks a lot for providing this.

serge-sans-paille commented 1 year ago

yeah, that's weird, I'll have a look. Thanks for reporting

serge-sans-paille commented 1 year ago

I don't have the issue with

% g++ --version
g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
serge-sans-paille commented 1 year ago

Can you confirm #151 does the trick?

amosnier commented 1 year ago

Can you confirm #151 does the trick?

It does. Thanks.