<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/148038>148038</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            std::allocator cannot deallocate memory of derived class through pointer to parent class during the compile-time evaluation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kridenberg
      </td>
    </tr>
</table>

<pre>
    As far as I understand requirement of the equality of the std::allocator class it should be possible and should be well-defined. At least till pointers of the base and derived classes point to the same memory address. Example on the Compiler Explorer: https://godbolt.org/z/WcsYE94e4 and below:

```
#include <memory>

#define USE_CONSTEXPR 1
#if USE_CONSTEXPR
#   define CONSTEXPR constexpr
#else
#   define CONSTEXPR
#endif // USE_CONSTEXPR

struct A
{
public:
    virtual ~A() noexcept = default;

public:
    int a = 0;
};

struct C
{
public:
    int c = 0;
};

struct B
    : A
 , C
{
public:
    int b = 1;
};

template<typename derived_type_t>
inline CONSTEXPR auto allocate() -> derived_type_t*
{
 std::allocator<derived_type_t> derived_allocator;
    derived_type_t* ptr {derived_allocator.allocate(1)};
    return ptr;
}

template<typename base_type_t>
inline CONSTEXPR auto deallocate(base_type_t* ptr) -> void
{
 std::allocator<base_type_t> base_allocator;
 base_allocator.deallocate(ptr, 1);
}

template<typename base_type_t, typename derived_type_t>
inline CONSTEXPR auto test() noexcept -> bool
{
 base_type_t* base_ptr {allocate<derived_type_t>()};
 deallocate<base_type_t>(base_ptr);
    return true;
}

auto main() -> int
{
    CONSTEXPR auto v = test<A, B>();
    return 0;
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVc-P8jYQ_WvMZbQoscMChxxCPpB6aat-rdqeVk48gFvHzmeP2d0e-rdX-cECYVfbVkJCcebNm_fGk5Eh6INFzNliwxZfZjLS0fn8T68V2gr9YVY59ZoXAfbSgwz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