foonathan / type_safe

Zero overhead utilities for preventing bugs at compile time
https://type_safe.foonathan.net
MIT License
1.54k stars 122 forks source link

Use alignas rather than deprecated std::aligned_storage #145

Closed davidhunter22 closed 1 year ago

davidhunter22 commented 1 year ago

fixes foonathan/type_safe#144

davidhunter22 commented 1 year ago

Ah so std::byte is a C++ 17 thing. Do you want me to use something like 'char' instead? I can also do conditional code based on C++ 14 or 17 and greater. Note I did note the README does not mention minimum language or compiler versions, I assume it is C++ 14, if it is it may better to require this in the CMake so you don't get as far as trying to compile code.

foonathan commented 1 year ago

Just use unsigned char instead; the project aims to be C++11 compatible.

davidhunter22 commented 1 year ago

I think I need to install some old compilers so I can check they work!

davidhunter22 commented 1 year ago

OK I am confused by the error

/__w/type_safe/type_safe/include/type_safe/reference.hpp:689:14:   required from 'class type_safe::function_ref<int(int, int)>'
/__w/type_safe/type_safe/test/reference.cpp:243:40:   required from here
/__w/type_safe/type_safe/include/type_safe/detail/aligned_union.hpp:45:67: error: requested alignment is not an integer constant

In the gcc48 build that is failing given the values are defined as

        static constexpr auto size_value      = detail::max(sizeof(Types)...);
        static constexpr auto alignment_value = detail::max(alignof(Types)...);

Is this one of those "the compiler may not actually make a constexpr a compile time constant" things?

foonathan commented 1 year ago

I've implemented the requested changes myself. Thanks for starting the PR.