Miscellaneous warnings and errors which showed up in GCC 12 #257
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.
Fix #255
At least, I think this will fix that issue, as originally reported. I have not been able to reproduce the original linker error, but by enabling LTO and testing with both GCC 10 and GCC 12 (after an Ubuntu upgrade), I flushed out a lot of ODR (one definition rule) warnings where template methods were specialized the same way in multiple translation units.
To fix the ODR warnings, and hopefully the original linker issue, I added
inline
specifiers to every non-constexpr
inline method I could find in the headers. I also separated the template methods from the static methods in theModified...
templatestructs
and put the template methods in an anonymous namespace. That makes their linkage private to each translation unit which instantiates them, so the linker cannot treat them as the same symbol (although it may still monomorphize them to remove duplicate code).While I was tracking that down, I decided to simplify the SFINAE template logic in the
Modified...
templatestructs
. I replaced/consolidated pretty much every reference to thestd::is_same_v<>
orstd::is_base_of_v<>
type_traits
with concepts and andstd::enable_if_t
withrequires
clauses on the template methods. They're all much easier to read now.Last of all, GCC 12 seems to have added some potential memory safety warnings which it evaluates at compile time. I found that it wanted me to pass keys (which are pretty much always
std::string_view
) by value rather thanconst
reference inSortedMap.h
. In a few tests where I copy strings into a byte vector to make a Base64response::IdType
, I needed to usestd::string_view
instead ofstd::string
to avoid hitting the small-string optimization and confusing the compile-time bounds checks.