beached / daw_json_link

Fast, convenient JSON serialization and parsing in C++
https://beached.github.io/daw_json_link/
Boost Software License 1.0
478 stars 31 forks source link

build failure on gcc 12 C++ 20 #454

Closed pauldreik closed 3 weeks ago

pauldreik commented 1 month ago

Using debian stable, with gcc 12.2.0 (currently 12.2.0-14), I get the following build failure on commit 85f5f3f3d15a27fa000733f758b157d2267a74c8 :

~/code$ git clone https://github.com/beached/daw_json_link.git
~/code$ cd daw_json_link
~/code/daw_json_link$ CXX=g++-12 cmake -B build-gcc12-cpp20 -S .  -GNinja -DDAW_ENABLE_TESTING=On  -DCMAKE_CXX_STANDARD=20
~/code/daw_json_link$ ninja -C build-gcc12-cpp20

# snip....
code/daw_json_link/include/daw/json/impl/daw_json_allocator_wrapper.h:58:87: error: typename std::allocator_traits<_Alloc>::rebind_traits is not a template [-fpermissive]
   58 |                           typename std::allocator_traits<T>::template rebind_traits<U>::type );
      |                                                                                       ^~
/home/banan/code/daw_json_link/include/daw/json/impl/daw_json_req_helper.h:108:17: note: in definition of macro DAW_JSON_MAKE_REQ_TYPE_ALIAS_TRAIT2

Using gcc12+cpp17 works fine, as well as gcc11+cpp20

beached commented 4 weeks ago

This is confusing, it is a template. http://eel.is/c++draft/allocator.traits#:~:text=rebind_traits

Do you have an example, I wonder if this is an issue with gcc 12

pauldreik commented 4 weeks ago

I just cloned the repo and then ran the cmake+build command above. All the code is in this repo. Or do I perhaps misunderstand what you mean? I edited the text to show the clone command as well.

I reproduced the same error also on debian testing, using gcc 12.4.0. gcc 13 and 14 work fine.

pauldreik commented 4 weeks ago

I made a reproducer on godbolt:

#include <memory>
#include <type_traits>

template <typename T, typename U>
inline constexpr bool allocator_has_rebind_v = requires {
    typename std::allocator_traits<T>::template rebind_traits<U>::type;
};
  1. gcc 11.3: fail with different error
  2. gcc 11.4: ok
  3. gcc 12.1: fail
  4. gcc 12.2: fail
  5. gcc 12.3: fail
  6. gcc 12.4: fail
  7. gcc 13.1: fail
  8. gcc 13.2: fail
  9. gcc 13.3: ok
  10. gcc 14.1: ok
  11. gcc 14.2: ok
  12. gcc trunk: ok
  13. clang 19 libc++: ok
  14. clang 19 libstdc++: ok
beached commented 4 weeks ago

Glad they fixed it. I am just testing, but I will add a compilation define for all of these that disables them and uses SFINAE/specialization, the pre-20 way.

beached commented 4 weeks ago

Should be fixed with https://github.com/beached/daw_json_link/commit/f7bf7018706228d63212d0d45eb5f207fe310f52

pauldreik commented 4 weeks ago

Thanks for fixing it! It now compiles.

I wonder - why was this not caught in CI? it seems like gcc 12 is tested with C++20. EDIT: it was caught in CI: https://github.com/beached/daw_json_link/actions/runs/11529159711/job/32097261291

beached commented 3 weeks ago

https://github.com/beached/daw_json_link/releases/tag/v3.29.2