Hi,

in order to avoid this ICE on invalid, I think it makes sense to explicitly check for try-block in massage_constexpr_body, since 7.1.5/4 explicitly rules out for constexpr constructors such function-body.

Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////
/cp
2012-04-17  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/52599
        * semantics.c (massage_constexpr_body): Check for function-try-block
        as constructor function-body.

/testsuite
2012-04-17  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/52599
        * g++.dg/cpp0x/constexpr-ctor10.C: New.
Index: testsuite/g++.dg/cpp0x/constexpr-ctor10.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-ctor10.C   (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-ctor10.C   (revision 0)
@@ -0,0 +1,6 @@
+// PR c++/52599
+// { dg-options -std=c++11 }
+
+struct foo {
+  constexpr foo() try { } catch(...) { };  // { dg-error "constructor" }
+};
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 186523)
+++ cp/semantics.c      (working copy)
@@ -6001,8 +6001,18 @@ static tree
 massage_constexpr_body (tree fun, tree body)
 {
   if (DECL_CONSTRUCTOR_P (fun))
-    body = build_constexpr_constructor_member_initializers
-      (DECL_CONTEXT (fun), body);
+    {
+      if (TREE_CODE (body) == BIND_EXPR
+         && TREE_CODE (BIND_EXPR_BODY (body)) == TRY_BLOCK)
+       {
+         error ("body of %<constexpr%> constructor cannot be a "
+                "function-try-block");
+         return error_mark_node;
+       }
+
+      body = build_constexpr_constructor_member_initializers
+       (DECL_CONTEXT (fun), body);
+    }
   else
     {
       if (TREE_CODE (body) == EH_SPEC_BLOCK)

Reply via email to