build: avoid ODR violation from different struct layout per TU#326
Merged
vincent-richard merged 1 commit intokisli:masterfrom Jul 21, 2025
Merged
build: avoid ODR violation from different struct layout per TU#326vincent-richard merged 1 commit intokisli:masterfrom
vincent-richard merged 1 commit intokisli:masterfrom
Conversation
When building with ASAN, the linker warns about struct declarations being different
between TUs, which is undefined behavior.
```
[ 1%] Linking CXX shared library build/lib/libwmime.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/wmime.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -D_REENTRANT=1 -W -Wall -pedantic -Wpointer-arith
-Wold-style-cast -Wconversion -Wcast-align -Wno-long-long -fvisibility=hidden
-fvisibility-inlines-hidden -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
-fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables
-fstack-clash-protection -Werror=return-type -flto=auto -g -O0 -ggdb3
-fsanitize=address,undefined -lasan -lubsan
-Wl,--dependency-file=CMakeFiles/wmime.dir/link.d -flto=auto -Wl,--as-needed
-Wl,--no-undefined -Wl,-z,now -lasan -lubsan -shared -Wl,-soname,libwmime.so.2
-o build/lib/libwmime.so.2.0.0 CMakeFiles/wmime.dir/src/vmime/address.cpp.o...
~/src/vmime/security/sasl/SASLContext.hpp:47:20:
warning: type ‘struct SASLContext’ violates the C++ One Definition Rule [-Wodr]
47 | class VMIME_EXPORT SASLContext : public object, public enable_shared_from_this <SASLContext> {
~/src/vmime/security/sasl/SASLContext.hpp:47:20: note: a different type is defined in another translation unit
47 | class VMIME_EXPORT SASLContext : public object, public enable_shared_from_this <SASLContext> {
~/src/vmime/security/sasl/SASLContext.hpp:123:15: note: the first difference of corresponding definitions is field ‘m_gsaslContext’
123 | void* m_gsaslContext;
~/src/vmime/security/sasl/SASLContext.hpp:121:16: note: a field of same name but different type is defined in another translation unit
121 | Gsasl* m_gsaslContext;
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When building with ASAN, the linker warns about struct declarations being different between TUs, which is undefined behavior.