https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98798

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jwakely at redhat dot com
           Assignee|marxin at gcc dot gnu.org          |unassigned at gcc dot 
gnu.org
             Status|ASSIGNED                    |NEW

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #1)
> Confirmed, reduced test-case:
> 
> $ cat pr98798.C
> #include <iostream>
> #include <memory>
> 
> class alignas(32) Foo
> {
> public :
>     char x;
> 
>     void * operator new[ ] (size_t s, std::align_val_t a)
>     {
>       __builtin_printf ("s: %d, a: %d\n", s, a);
>         return aligned_alloc(static_cast<size_t>(a), s);
>     }
> 
>     void operator delete[ ] (void *p, size_t s, std::align_val_t a)
>     {
>     }
> };
> 
> int main()
> {
>   auto p = std::make_unique<Foo[]>(3);
> }
> 
> I'm going to take a look.

I think it's a bug in libstdc++ and one can see it with valgrind:

g++-10 pr98798.C -std=c++17 -g && valgrind ./a.out 
==10004== Memcheck, a memory error detector
==10004== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==10004== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==10004== Command: ./a.out
==10004== 
s: 96, a: 32
==10004== Invalid read of size 8
==10004==    at 0x4013B3: std::enable_if<std::is_convertible<Foo (*) [], Foo
(*) []>::value, void>::type std::default_delete<Foo []>::operator()<Foo>(Foo*)
const (unique_ptr.h:120)
==10004==    by 0x401304: std::unique_ptr<Foo [], std::default_delete<Foo []>
>::~unique_ptr() (unique_ptr.h:612)
==10004==    by 0x40119A: main (pr98798.C:22)
==10004==  Address 0x4da70f8 is 8 bytes before a block of size 96 alloc'd
==10004==    at 0x483C118: memalign (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==10004==    by 0x401231: Foo::operator new[](unsigned long, std::align_val_t)
(pr98798.C:12)
==10004==    by 0x40127E: std::_MakeUniq<Foo []>::__array std::make_unique<Foo
[]>(unsigned long) (unique_ptr.h:968)
==10004==    by 0x40118E: main (pr98798.C:22)

@Jonathan: Can you please take a look?

Reply via email to