Do not assume the PRI macros are still available - #191
Merged
Conversation
__STDC_FORMAT_MACROS only has an effect when nothing has included <inttypes.h> yet. NetBSD reaches the PRI macros through <sys/inttypes.h>, which gates them on that macro for C++ before C++11 and sits behind an include guard, so a header included earlier settles the question and the define here arrives too late. The condition now requires PRId64 and PRIu64 to actually be defined before using them, and takes the double fallback otherwise. That is a capability test rather than a proxy, and it does not depend on include order. test/inttypes_include.cpp covers it the way stdint_include.c covers the stdint case: <inttypes.h> first, then utest.h, compiled as C++98.
test20.cpp was compiled with -std=c++20 unconditionally. GCC 8 and clang 9 only accept the pre-release spelling -std=c++2a, and GCC 7 and older accept neither, so on those compilers the build stops before running anything. The file now drops the standard flag when neither spelling is available and is compiled at the compiler default, which is what already happens for test11.c without c_std_11 and on MSVC, where no -std flag is passed at all.
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.
__STDC_FORMAT_MACROSonly has an effect when nothing has included<inttypes.h>yet. NetBSD reaches thePRImacros through<sys/inttypes.h>:Behind an include guard, so whichever header gets there first settles it and
the define here arrives too late.
<sys/param.h>includes it, and so doesanything else that reaches
<inttypes.h>— a consumer including its ownheaders before
utest.his enough.That is not hypothetical. It surfaced in sheredom/subprocess.h#113 on NetBSD
9.4 and 10.1, where
test98.cppincludessubprocess.hfirst:What this does
Requires
PRId64andPRIu64to actually be defined before using them, andtakes the existing
doublefallback otherwise — a capability test rather thana proxy for one, so include order stops mattering.
test/inttypes_include.cppcovers it the waystdint_include.ccovers thestdintcase:<inttypes.h>first, thenutest.h, compiled as C++98.Verified against a stub
<inttypes.h>that exposes noPRImacros, which iswhat NetBSD looks like in C++98:
utest.hmainerror: expected ')' before 'PRIu64'Second commit, unrelated but small
test20.cppwas compiled with-std=c++20unconditionally. GCC 8 and clang 9only accept
-std=c++2a, and GCC 7 and older accept neither, so on those thebuild stops before running anything — NetBSD 9.4 ships GCC 7.5.0. It now drops
the standard flag when neither spelling is available, which is what already
happens for
test11.cwithoutc_std_11and on MSVC.Happy to split that into its own PR if you would rather.
Not included
A portability matrix here, which is what found this. It needs the vendored
test/subprocess.hrefreshed first — that copy predatessheredom/subprocess.h#104, so
maindoes not build against current glibcwithout
_GNU_SOURCE. Separate PR, if you want it.