In this PR we're emitting -Wnoexcept warnings about potentially-throwing NSDMIs
when computing the noexcept specification of a class's defaulted default
constructor. Although these warnings are in some sense valid, this patch takes
the route of suppressing them, because:
1. the warning message is confusing in its current form;
2. warning for 'struct C { B b = B(); };' but not for 'struct C { B b; };'
is inconsistent; and
3. emitting a warning here arguably doesn't fall under the umbrella of
-Wnoexcept, whose documentation says it warns only when a
noexcept-expression evaluates to false, but there are no
noexcept-expressions here.
gcc/cp/ChangeLog:
PR c++/93805
* except.c (maybe_noexcept_warning): Add TODO comment.
* method.c (walk_field_subobs): Pass tf_none to expr_noexcept_p.
gcc/testsuite/ChangeLog:
PR c++/93805
* g++.dg/warn/Wnoexcept2.C: New test.
+2020-03-23 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/93805
+ * except.c (maybe_noexcept_warning): Add TODO.
+ * method.c (walk_field_subobs): Pass tf_none to expr_noexcept_p.
+
2020-03-23 nathans <nathan@acm.org>
PR c++/94044
static GTY(()) vec<pending_noexcept, va_gc> *pending_noexcept_checks;
/* FN is a FUNCTION_DECL that caused a noexcept-expr to be false. Warn if
- it can't throw. */
+ it can't throw.
+
+ TODO: Consider extending -Wnoexcept to do something like walk_subtrees in the
+ case of a defaulted function that obtained a noexcept(false) spec. */
static void
maybe_noexcept_warning (tree fn)
if (nsdmi == error_mark_node)
*spec_p = error_mark_node;
else if (*spec_p != error_mark_node
- && !expr_noexcept_p (nsdmi, complain))
+ && !expr_noexcept_p (nsdmi, tf_none))
*spec_p = noexcept_false_spec;
}
/* Don't do the normal processing. */
+2020-03-23 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/93805
+ * g++.dg/warn/Wnoexcept2.C: New test.
+
2020-03-23 Jakub Jelinek <jakub@redhat.com>
PR c++/91993
--- /dev/null
+// PR c++/93805
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wnoexcept" }
+
+struct B
+{
+ B() {}
+};
+
+struct C
+{
+ B b = B();
+};
+
+C c; // { dg-bogus "noexcept-expression" }