[all-commits] [llvm/llvm-project] 687bd7: [ADT][NFC] Fix compilation of headers under C++23

Adrian Vogelsgesang via All-commits all-commits at lists.llvm.org
Thu May 11 15:21:54 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 687bd77e2c26487cba727aacfa7067dd01286be0
      https://github.com/llvm/llvm-project/commit/687bd77e2c26487cba727aacfa7067dd01286be0
  Author: Adrian Vogelsgesang <avogelsgesang at salesforce.com>
  Date:   2023-05-11 (Thu, 11 May 2023)

  Changed paths:
    M llvm/include/llvm/ADT/APFloat.h
    M llvm/include/llvm/IR/ModuleSummaryIndex.h

  Log Message:
  -----------
  [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




More information about the All-commits mailing list