Hi,

this is a rejects-valid with constexpr & noexcept, noticed by Daniel (and myself time ago). I find it pretty annoying. Anyway, the issue is, we reject:

constexpr bool ok() noexcept
{
  typedef int type;
  return true;
}

constexpr auto x = ok();

because of the noexcept. What happens is that massage_constexpr_body looks inside MUST_NOT_THROW_EXPR but then doesn't notice that body is still a BIND_EXPR.

Thus the obvious idea is processing the latter as we would do if the noexcept were not there and that indeed fixes the issue without regressions, but I'm not sure if we shouldn't recurse / iterate more generically (or do indeed something else entirely)

Thanks,
Paolo.

//////////////////
Index: testsuite/g++.dg/cpp0x/constexpr-noexcept6.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-noexcept6.C        (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-noexcept6.C        (revision 0)
@@ -0,0 +1,10 @@
+// PR c++/51305
+// { dg-options -std=c++0x }
+
+constexpr bool ok() noexcept
+{
+  typedef int type;
+  return true;
+}
+
+constexpr auto x = ok();
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 182556)
+++ cp/semantics.c      (working copy)
@@ -6003,7 +6003,11 @@ massage_constexpr_body (tree fun, tree body)
       if (TREE_CODE (body) == EH_SPEC_BLOCK)
         body = EH_SPEC_STMTS (body);
       if (TREE_CODE (body) == MUST_NOT_THROW_EXPR)
-       body = TREE_OPERAND (body, 0);
+       {
+         body = TREE_OPERAND (body, 0);
+         if (TREE_CODE (body) == BIND_EXPR)
+           body = BIND_EXPR_BODY (body);
+       }
       body = constexpr_fn_retval (body);
     }
   return body;

Reply via email to