Improve detection of mismatched header versions #683
Merged
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.
The existing mismatch detection catches the case where a single *.cpp file includes headers from different versions of the C++/WinRT headers. However, the error message isn't very helpful in tracking down the two versions that didn't match.
Move the
#defineofCPPWINRT_VERSIONoutside the header guard and repeat the definition after thestatic_assert. This makes mismatches easier to diagnose because the compiler will tell youin the case where you
#includetwo incompatible versions ofbase.h, orin the case where you use a projection header file that is not compatible with the
base.hyou used.In both cases, the compiler will give you the path to the conflicting header files, making it easier to diagnose. In this case, you can see that you are mixing headers between apple and banana.
This takes advantage of the fact that it is legal to redefine a macro provided you redefine it to something that exactly matches its existing definition. We have everybody define the
CPPWINRT_VERSIONmacro to be the version they expect, and the compiler will call out any discrepancy within a single translation unit.A more insidious error that had previous gone undetected is the case where you link together *.cpp files that disagree on the C++/WinRT version.
We address this by using MSVC's detect_mismatch pragma to stamp each object file with the version of C++/WinRT it was compiled with, and the linker will complain if object files with different stamps are linked together: