sccn / liblsl

C++ lsl library for multi-modal time-synched data transmission over the local network
Other
107 stars 63 forks source link

MSVC warnings: consumer_queue and stream_inlet_impl not aligned 64 #142

Closed cboulay closed 2 years ago

cboulay commented 2 years ago

After some updates to the core, it's worth taking some time to look at compiler warnings.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\memory(1588): warning C4316: 'std::_Ref_count_obj2<_Ty>': object allocated on the heap may not be aligned 64
          with
          [
              _Ty=lsl::consumer_queue
          ]
  ..\..\..\src\send_buffer.cpp(12): note: see reference to function template instantiation 'std::shared_ptr<lsl::consumer_queue> std::make_shared<lsl::consumer_queue,int&,std::shared_ptr<lsl::send_buffer>>(int &,std::shared_ptr<lsl::send_buffer> &&)' being compiled
D:\Tools\Neurophys\labstreaminglayer\LSL\liblsl\src\lsl_c_api_helpers.hpp(83): warning C4316: 'lsl::stream_inlet_impl': object allocated on the heap may not be aligned 64
  ..\..\..\src\lsl_inlet_c.cpp(21): note: see reference to function template instantiation 'Type *create_object_noexcept<lsl::stream_inlet_impl,lsl::stream_info_impl&,int,int32_t&,bool>(lsl::stream_info_impl &,int &&,int32_t &,bool &&) noexcept' being compiled
          with
          [
              Type=lsl::stream_inlet_impl
          ]
chausner-audeering commented 2 years ago

In some versions of MSVC, it leads to an error instead of warning:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\type_traits(1271): error C2338: You've instantiated std::aligned_storage<Len, Align> with an extended alignment (in other words, Align > alignof(max_align_t)). Before VS 2017 15.8, the member type would non-conformingly have an alignment of only alignof(max_align_t). VS 2017 15.8 was fixed to handle this correctly, but the fix inherently changes layout and breaks binary compatibility (only for uses of aligned_storage with extended alignments). Please define either (1) _ENABLE_EXTENDED_ALIGNED_STORAGE to acknowledge that you understand this message and that you actually want a type with an extended alignment, or (2) _DISABLE_EXTENDED_ALIGNEDSTORAGE to silence this message and get the old non-conformant behavior. (compiling source file C:\J\w\BuildSingleReference@5.conan\data\liblsl\1.16.0_\\build\6b414038193353d88ee898dc370d1f19ef53d0aa\source_subfolder\src\sendbuffer.cpp) [C:\J\w\BuildSingleReference@5.conan\data\liblsl\1.16.0_\\build\6b414038193353d88ee898dc370d1f19ef53d0aa\build_subfolder\source_subfolder\lslobj.vcxproj]