Control: retitle -1 False positive -Warray-bounds warning
Control: forwarded -1 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110764

[Trying again without throwing entropy to submit@bugs.d.o.]

Hi,

Following Jonathan Wakely's remark in atomic_queue bug tracker,
I retitle the entry to something not as misleading.  Also Thanks
Jonathan for the bug open in Gcc tracker!

For convenience, the reproducer is:

        $ cat real-reproducer.cpp 
        #include <iostream>
        #include <thread>
        #include <vector>
        
        void g(int n);
        
        void g(int n) {
            std::cout << "consume: " << n << std::endl;
        }
        
        int main(void) {
            std::vector<std::thread> threads(1);
            // The compiler error comes from the two threads below.
            threads[0] = std::thread(g, 42);
            threads[1] = std::thread(g, 42);
            threads[0].join();
            threads[1].join();
            return (0);
        }

        $ g++ real-reproducer.cpp -Warray-bounds -O2
        In file included from /usr/include/c++/13/bits/exception_ptr.h:41,
                         from /usr/include/c++/13/exception:164,
                         from /usr/include/c++/13/ios:41,
                         from /usr/include/c++/13/ostream:40,
                         from /usr/include/c++/13/iostream:41,
                         from real-reproducer.cpp:1:
        In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, 
std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, 
_Tp&) [with _Tp = thread::id]’,
            inlined from ‘void std::thread::swap(std::thread&)’ at 
/usr/include/c++/13/bits/std_thread.h:193:16,
            inlined from ‘std::thread& std::thread::operator=(std::thread&&)’ 
at /usr/include/c++/13/bits/std_thread.h:187:11,
            inlined from ‘int main()’ at real-reproducer.cpp:15:35:
        /usr/include/c++/13/bits/move.h:198:7: warning: array subscript 1 is 
outside array bounds of ‘std::thread [1]’ [-Warray-bounds=]
          198 |       __a = _GLIBCXX_MOVE(__b);
              |       ^~~
        In file included from 
/usr/include/x86_64-linux-gnu/c++/13/bits/c++allocator.h:33,
                         from /usr/include/c++/13/bits/allocator.h:46,
                         from /usr/include/c++/13/string:43,
                         from /usr/include/c++/13/bits/locale_classes.h:40,
                         from /usr/include/c++/13/bits/ios_base.h:41,
                         from /usr/include/c++/13/ios:44:
        In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, 
const void*) [with _Tp = std::thread]’,
            inlined from ‘static _Tp* 
std::allocator_traits<std::allocator<_CharT> >::allocate(allocator_type&, 
size_type) [with _Tp = std::thread]’ at 
/usr/include/c++/13/bits/alloc_traits.h:482:28,
            inlined from ‘std::_Vector_base<_Tp, _Alloc>::pointer 
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = 
std::thread; _Alloc = std::allocator<std::thread>]’ at 
/usr/include/c++/13/bits/stl_vector.h:378:33,
            inlined from ‘std::_Vector_base<_Tp, _Alloc>::pointer 
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = 
std::thread; _Alloc = std::allocator<std::thread>]’ at 
/usr/include/c++/13/bits/stl_vector.h:375:7,
            inlined from ‘void std::_Vector_base<_Tp, 
_Alloc>::_M_create_storage(std::size_t) [with _Tp = std::thread; _Alloc = 
std::allocator<std::thread>]’ at /usr/include/c++/13/bits/stl_vector.h:395:44,
            inlined from ‘std::_Vector_base<_Tp, 
_Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = 
std::thread; _Alloc = std::allocator<std::thread>]’ at 
/usr/include/c++/13/bits/stl_vector.h:332:26,
            inlined from ‘std::vector<_Tp, _Alloc>::vector(size_type, const 
allocator_type&) [with _Tp = std::thread; _Alloc = 
std::allocator<std::thread>]’ at /usr/include/c++/13/bits/stl_vector.h:554:47,
            inlined from ‘int main()’ at real-reproducer.cpp:12:39:
        /usr/include/c++/13/bits/new_allocator.h:147:55: note: at offset 8 into 
object of size 8 allocated by ‘operator new’
          147 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * 
sizeof(_Tp)));
              |                                                       ^

This doesn't explain why the issue didn't appear in Fedora using
Gcc 13.1.1, but the most likely explanation could be the use of
-Wno-error build flag, which would make sense as a distributor.

Have a nice day,  :)
-- 
  .''`.  Étienne Mollier <emoll...@debian.org>
 : :' :  gpg: 8f91 b227 c7d6 f2b1 948c  8236 793c f67e 8f0d 11da
 `. `'   sent from /dev/pts/3, please excuse my verbosity
   `-    on air: Saga - Always There

Attachment: signature.asc
Description: PGP signature

Reply via email to