[all-commits] [llvm/llvm-project] dadbe8: [libc++] Fix std::to_address(array).

Quuxplusone via All-commits all-commits at lists.llvm.org
Tue Sep 7 10:56:53 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dadbe88a1387e7b1fe4417fa4b64234ffc83c878
      https://github.com/llvm/llvm-project/commit/dadbe88a1387e7b1fe4417fa4b64234ffc83c878
  Author: Arthur O'Dwyer <arthur.j.odwyer at gmail.com>
  Date:   2021-09-07 (Tue, 07 Sep 2021)

  Changed paths:
    M libcxx/include/__memory/pointer_traits.h
    M libcxx/test/libcxx/utilities/memory/pointer.conversion/to_address.pass.cpp
    A libcxx/test/libcxx/utilities/memory/pointer.conversion/to_address_on_funcptr.verify.cpp
    A libcxx/test/libcxx/utilities/memory/pointer.conversion/to_address_on_function.verify.cpp
    M libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp
    A libcxx/test/std/utilities/memory/pointer.conversion/to_address_on_funcptr.verify.cpp
    A libcxx/test/std/utilities/memory/pointer.conversion/to_address_on_function.verify.cpp

  Log Message:
  -----------
  [libc++] Fix std::to_address(array).

There were basically two bugs here:

When C++20 `to_address` is called on `int arr[10]`, then `const _Ptr&` becomes
a reference to a const array, and then we dispatch to `__to_address<const int(&)[10]>`,
which, oops, gives us a `const int*` result instead of an `int*` result.
Solution: We need to provide the two standard-specified overloads of
`std::to_address` in exactly the same way that we provide two overloads
of `__to_address`.

When `__to_address` is called on a pointer type, `__to_address(const _Ptr&)`
is disabled so we successfully avoid trying to instantiate pointer_traits of
that pointer type. But when it's called on an array type, it's not disabled
for array types, so we go ahead and instantiate pointer_traits<int[10]>,
which goes boom. Solution: We need to disable `__to_address(const _Ptr&)`
for both pointer and array types. Also disable it for function types,
so that they get the nice error message; and put a test on it.

Differential Revision: https://reviews.llvm.org/D109331




More information about the All-commits mailing list