Avoid brittle wcscpy_s and wcscat_s defines on mingw - #198
Open
mstorsjo wants to merge 1 commit into
Open
Conversation
These wcscpy_s and wcscat_s fallback defines seem to be inteded for older versions of MSVC. When building in mingw mode, _MSC_VER isn't defined at all. Previously this led to these defines being used, which was harmless at time time. After mingw-w64/mingw-w64@9dff64a in mingw-w64, these fallback defines break using mingw-w64 headers; the expansion of wcscpy_s into two separate statements breaks use of wcscpy_s function in an expression context, leading to errors like this: In file included from /home/martin/code/libvpl/libvpl/src/windows/mfx_dispatcher.cpp:14: In file included from /home/martin/clang-nightly/x86_64-w64-mingw32/include/windows.h:114: /home/martin/clang-nightly/x86_64-w64-mingw32/include/stralign.h:208:67: error: expected ')' 208 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); | ^ /home/martin/code/libvpl/libvpl/src/windows/mfx_dispatcher_defs.h:22:24: note: expanded from macro 'wcscpy_s' 22 | (void)(to_size); \ | ^ /home/martin/clang-nightly/x86_64-w64-mingw32/include/stralign.h:208:66: note: to match this '(' 208 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); | ^ /home/martin/clang-nightly/x86_64-w64-mingw32/include/stralign.h:208:67: error: cannot initialize return object of type 'PUWSTR' (aka 'wchar_t *') with an rvalue of type 'void' 208 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/martin/code/libvpl/libvpl/src/windows/mfx_dispatcher_defs.h:22:9: note: expanded from macro 'wcscpy_s' 22 | (void)(to_size); \ | ^~~~~~~~~~~~~~~ In file included from /home/martin/code/libvpl/libvpl/src/windows/mfx_dispatcher.cpp:14: In file included from /home/martin/clang-nightly/x86_64-w64-mingw32/include/windows.h:114: /home/martin/clang-nightly/x86_64-w64-mingw32/include/stralign.h:208:150: error: extraneous ')' before ';' 208 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); | ^ 3 errors generated. Avoid this issue by simply limiting the fallback wcscpy_s and wcscat_s defines to older MSVC versions, which seems to be the original intent, avoiding defining them on mingw targets, that don't need them.
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.
These wcscpy_s and wcscat_s fallback defines seem to be inteded for older versions of MSVC. When building in mingw mode, _MSC_VER isn't defined at all.
Previously this led to these defines being used, which was harmless at time time.
After mingw-w64/mingw-w64@9dff64a in mingw-w64, these fallback defines break using mingw-w64 headers; the expansion of wcscpy_s into two separate statements breaks use of wcscpy_s function in an expression context, leading to errors like this:
Avoid this issue by simply limiting the fallback wcscpy_s and wcscat_s defines to older MSVC versions, which seems to be the original intent, avoiding defining them on mingw targets, that don't need them.