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

            Bug ID: 90992
           Summary: -Wnoexcept produce false positive
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adrien.hamelin+gcc at gmail dot com
  Target Milestone: ---

Created attachment 46516
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46516&action=edit
Minimal case to reproduce, compile with "g++ -Wnoexcept gcc_bug.cpp"

We seem to have found a bug in g++, it generates a false warning that a
constructor could be noexcept when it has a member that is not.

See the attached file for a minimal test case, compiled with "g++ -Wnoexcept
gcc_bug.cpp", it generates:

/usr/include/c++/9/ext/new_allocator.h: In instantiation of ‘void
__gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up =
Automatic; _Args = {int}; _Tp = Automatic]’:
/usr/include/c++/9/bits/alloc_traits.h:482:2:   required from ‘static void
std::allocator_traits<std::allocator<_Tp1>
>::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&,
_Up*, _Args&& ...) [with _Up = Automatic; _Args = {int}; _Tp = Automatic;
std::allocator_traits<std::allocator<_Tp1> >::allocator_type =
std::allocator<Automatic>]’
/usr/include/c++/9/bits/vector.tcc:115:30:   required from ‘void
std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int}; _Tp =
Automatic; _Alloc = std::allocator<Automatic>]’
gcc_bug.cpp:25:25:   required from here
gcc_bug.cpp:16:5: warning: but ‘Automatic::Automatic(size_t)’ does not throw;
perhaps it should be declared ‘noexcept’ [-Wnoexcept]
   16 |     Automatic(size_t bla) : Bla(bla) {};
      |     ^~~~~~~~~
gcc_bug.cpp:14:7: warning: but ‘Automatic::~Automatic()’ does not throw;
perhaps it should be declared ‘noexcept’ [-Wnoexcept]
   14 | class Automatic {
      |       ^~~~~~~~~

In our case (in a more complex code base), the warning happens on the
automatically generated move constructor, which is not noexcept as it should
but still generates that warning. In our case also just declaring the move
constructor as default seems to hide the warning, though it doesn't in the
minimal test case I provide.

Reply via email to