[CXX-1678] std::aligned_storage build failure with extra alignment Created: 29/Oct/18  Updated: 28/Oct/23  Resolved: 27/Nov/18

Status: Closed
Project: C++ Driver
Component/s: BSON
Affects Version/s: 3.4.0
Fix Version/s: 3.5.0

Type: New Feature Priority: Major - P3
Reporter: Zolotov Pavel Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: C++11, VisualStudio, build-failure
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows \ Microsoft Visual Studio 2015 v15.8+


Issue Links:
Depends
Related
related to CDRIVER-2813 Remove BSON_EXTRA_ALIGNMENT option Backlog
related to CXX-1697 Test with C driver extra alignment on Closed

 Description   

Visual Studio (v15.8+) project 'bsoncxx' (and 'bsoncxx_testing') generated by CMake has compile error in 'core.cpp' (static assert in 'type_traits'):

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_ALIGNED_STORAGE to silence this message and get the old non-conformant behavior.
bsoncxx
c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.15.26726\include\type_traits
1271 



 Comments   
Comment by Zolotov Pavel [ 28/Nov/18 ]

kevin.albertson, thank you!

Comment by Kevin Albertson [ 27/Nov/18 ]

Hi Zolotov, This has been fixed on master, and should no longer require the workarounds I described above. Although it is still recommended that you configure the C driver with -DENABLE_EXTRA_ALIGNMENT=OFF regardless.

Comment by Githook User [ 27/Nov/18 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@10gen.com', 'username': 'kevinAlbs'}

Message: CXX-1678 Fix VS2017 build
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/c124f9d0b3671c8b62066510cd415af7d83ec929

Comment by Zolotov Pavel [ 07/Nov/18 ]

kevin.albertson,

thank you for the presented solution.

Comment by Kevin Albertson [ 06/Nov/18 ]

Hi Zolotov,

I was able to reproduce this on VS 2017. As the error message indicates, there is code in the C++ driver trying to create a std::aligned_storage with alignment greater than alignof(max_align_t).

I'm still investigating the right solution. As a workaround, you do one of the following:
1. Reconfigure, compile, and install the C driver without extra alignment. The root of this issue is that the bson_t type in the C driver has 128 byte alignment by default. We'd like to change it but can't without breaking ABI compatibility. See CDRIVER-2813.
You can disable this extra alignment by configuring libmongoc with passing -DENABLE_EXTRA_ALIGNMENT=OFF to cmake:

2. Define _ENABLE_EXTENDED_ALIGNED_STORAGE in the preprocessor Visual Studio project configuration.

Comment by A. Jesse Jiryu Davis [ 31/Oct/18 ]

Thanks for the report! We aren't currently testing with Visual Studio 2017, let us know if you find a solution.

Comment by Zolotov Pavel [ 30/Oct/18 ]

I made a mistake in 'Environment'. 

Correct description is 'Microsoft Visual Studio 2017 v15.8+'.

Generated at Wed Feb 07 22:03:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.