[ADT][NFC] Fix compilation of headers under C++23
authorAdrian Vogelsgesang <avogelsgesang@salesforce.com>
Thu, 4 May 2023 12:20:29 +0000 (12:20 +0000)
committerAdrian Vogelsgesang <avogelsgesang@salesforce.com>
Thu, 11 May 2023 22:21:36 +0000 (22:21 +0000)
commit687bd77e2c26487cba727aacfa7067dd01286be0
tree415b2ba6fcce467ff6254e615adb4aaf9909b323
parentb10e9427b96e6bfb242853e9e8cfbb5031890a89
[ADT][NFC] Fix compilation of headers under C++23

`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

Differential Revision: https://reviews.llvm.org/D149854
llvm/include/llvm/ADT/APFloat.h
llvm/include/llvm/IR/ModuleSummaryIndex.h