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

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reduced test case:

$ cat 93805.C
struct B
{
  B() {}
};

struct C
{
  B b = B();
};

C c;
$ g++ -Wnoexcept 93805.C
93805.C:11:3: warning: noexcept-expression evaluates to ‘false’ because of a
call to ‘B::B()’ [-Wnoexcept]
   11 | C c;                                   
      |   ^                                    
93805.C:3:3: note: but ‘B::B()’ does not throw; perhaps it should be declared
‘noexcept’
    3 |   B() {}                               
      |   ^                                    



The commit in question adds a complain parameter to get_defaulted_eh_spec and
passes it down to synthesized_method_walk, and we eventually call
expr_noexcept_p in walk_field_subops with complain=tf_warning_or_error instead
of with complain=tf_none originally, which is the immediate cause of the
warning.

We're calling expr_noexcept_p from there to determine whether the NSDMI of C::b
is noexcept (so that we can determine the exception specification of C's
synthesized default constructor), and we're warning because the NSDMI of C::b
is not noexcept, but it could be if the non-throwing ctor B::B were marked
noexcept.

ISTM we can either disable the -Wnoexcept warning here, or we can keep the
warning but improve the warning message in this case.

Reply via email to