Repository navigation
Fix: make pcg_extras.hpp self-contained for PCG_NODISCARD - #18
Merged
Merged
Conversation
pcg_extras.hpp uses PCG_NODISCARD (generate_one, bounded_rand) but the macro was only defined in pcg_random.hpp, so including <pcg_extras.hpp> on its own failed with "unknown type name PCG_NODISCARD". Regression introduced when PCG_NODISCARD was added in a94acdf; the header compiled standalone before that. Define PCG_NODISCARD in pcg_extras.hpp under an #ifndef guard, and guard the existing definition in pcg_random.hpp so both orders work without a redefinition warning. Also drop a duplicated #include <limits> in pcg_extras.hpp. Verified: all three headers compile standalone with clang and MSVC at -std=c++14/17/20 (-Wall -Wextra -Wpedantic); ctest 42/42.
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.
Problem
pcg_extras.hppusesPCG_NODISCARD(ongenerate_oneandbounded_rand) but the macro was only ever defined inpcg_random.hpp. As a result the header no longer compiles when included on its own:This is a regression:
PCG_NODISCARDwas introduced for these two functions ina94acdf("Modernize codebase"), and before that commitpcg_extras.hpphad zero usages of the macro and compiled standalone without issue.178532b("Correct PCG_NODISCARD placement") did not address it.It only works by accident today because
pcg_random.hppdefines the macro on line 114 and includespcg_extras.hppon line 133. Anyone including<pcg_extras.hpp>directly — e.g. to usebounded_rand,seed_seq_fromorgenerate_one— hits the error immediately. This also affects downstream projects that vendor the header individually (SLiM shipseidos/pcg_extras.hppandeidos/pcg_random.hppas two separate files).Change
PCG_NODISCARDinpcg_extras.hppunder#ifndef PCG_NODISCARD, so the header is self-contained.pcg_random.hppin the same guard, so neither include order produces a redefinition warning.#include <limits>inpcg_extras.hpp.Header-only API and all generator output are unchanged.
Verification
Each header compiled standalone (
-I includewith only that header included):pcg_random.hpppcg_uint128.hpppcg_extras.hppextras->randomandrandom->extras) compile with no redefinition warning./std:c++14and/std:c++17,-Wall -Wextra -Wpedantic: clean.ctest: 42/42 passed.