This is an archive of the discontinued LLVM Phabricator instance.

[llvm][ADT] Fix compilation of headers under C++23
ClosedPublic

Authored by avogelsgesang on May 4 2023, 7:42 AM.

Details

Summary

DoubleAPFloat has a unique_ptr<APFloat[]> member. In
DoubleAPFloat::operator= and DoubleAPFloat::get{First,Second},
the methods of this unique_ptr are getting instantiated. At that
point APFloat is still only a forward declaration.

This triggers undefined behavior. So far, we were probaly just
lucky and the code compiled fine. However, with C++23
std::unique_ptr became constexpr, and clang (and other compilers) are
now diagnosing this latent bug as an error.

This commit fixes the issue by moving the function definitions
out of the class definition of DoubleAPFloat, after the declaration
of APFloat.

A similar issue exists in ModuleSummaryIndex.h, the fix is pretty
much identical.

Fixes #59784

Diff Detail

Event Timeline

avogelsgesang created this revision.May 4 2023, 7:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 7:42 AM
avogelsgesang requested review of this revision.May 4 2023, 7:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 7:42 AM

also fix ModuleSummaryIndex.h

avogelsgesang retitled this revision from [ADT] Fix compilation of `APFloat.h` under `--std=c++23` to [llvm][ADT] Fix compilation of headers under C++23.May 4 2023, 8:03 AM
avogelsgesang edited the summary of this revision. (Show Details)

not sure if I got the right audience of reviewers here. Please let me know if you think someone else would be better suited to review this

aaron.ballman accepted this revision.May 4 2023, 10:42 AM
aaron.ballman added a subscriber: aaron.ballman.

Thanks for the fix! LGTM, but please put NFC into the patch title so it's clear why no testing is needed for the changes.

This revision is now accepted and ready to land.May 4 2023, 10:42 AM
jloser accepted this revision.May 4 2023, 6:14 PM

You can remove [llvm]. llvm changes with a specific component tag doesn't need [llvm].

avogelsgesang edited the summary of this revision. (Show Details)

clang-format

This revision was landed with ongoing or failed builds.May 11 2023, 3:21 PM
This revision was automatically updated to reflect the committed changes.