[Bug middle-end/110764] New: [12/13/14 Regression] False positive -Warray-bounds warning swapping std::thread::id
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 21 10:43:07 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110764
Bug ID: 110764
Summary: [12/13/14 Regression] False positive -Warray-bounds
warning swapping std::thread::id
Product: gcc
Version: 12.3.1
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
#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);
}
Compiled with -Warray-bounds -O2 this gives a false positive:
In file included from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/exception_ptr.h:43,
from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/exception:168,
from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/ios:39,
from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/ostream:38,
from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/iostream:39,
from max.cc: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
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/std_thread.h:171:16,
inlined from ‘std::thread& std::thread::operator=(std::thread&&)’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/std_thread.h:165:11,
inlined from ‘int main()’ at max.cc:15:35:
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/move.h:205:7: warning: array
subscript 1 is outside array bounds of ‘std::thread [1]’ [-Warray-bounds]
205 | __a = _GLIBCXX_MOVE(__b);
| ^~~
In file included from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/allocator.h:46,
from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/string:41,
from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/locale_classes.h:40,
from
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/ios_base.h:41,
from /home/jwakely/gcc/12.1.0/include/c++/12.1.0/ios:42:
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
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/alloc_traits.h:464: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
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/stl_vector.h:378:33,
inlined from ‘void std::_Vector_base<_Tp,
_Alloc>::_M_create_storage(std::size_t) [with _Tp = std::thread; _Alloc =
std::allocator<std::thread>]’ at
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/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
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/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
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/stl_vector.h:552:47,
inlined from ‘int main()’ at max.cc:12:39:
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/bits/new_allocator.h:137:55: note:
at offset 8 into object of size 8 allocated by ‘operator new’
137 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
| ^
This started with r12-1992
More information about the Gcc-bugs
mailing list