PR c++/72849 - ICE with incomplete class.
authorJason Merrill <jason@redhat.com>
Tue, 9 Aug 2016 14:37:12 +0000 (10:37 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 9 Aug 2016 14:37:12 +0000 (10:37 -0400)
* constexpr.c (cxx_eval_constant_expression): Check
COMPLETE_TYPE_P before calling is_really_empty_class.
* class.c (is_really_empty_class): Don't call complete_type.

From-SVN: r239289

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/template/incomplete7.C [new file with mode: 0644]

index 7b746ca67fe7a99aba0e74b49a4d96167d325762..ffb0b85e0038a987c068e4a513f8c25dc3077669 100644 (file)
@@ -1,5 +1,10 @@
 2016-08-09  Jason Merrill  <jason@redhat.com>
 
+       PR c++/72849
+       * constexpr.c (cxx_eval_constant_expression): Check
+       COMPLETE_TYPE_P before calling is_really_empty_class.
+       * class.c (is_really_empty_class): Don't call complete_type.
+
        PR c++/56701
        * typeck.c (cp_build_addr_expr_1): Remove special *this handling.
 
index e7cfabd4b5948de3a75e7c9bfcd92ce5e91d1312..8249d9342299a2eb8fcb602924b130325b49073b 100644 (file)
@@ -8419,7 +8419,7 @@ is_really_empty_class (tree type)
 
       /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
         out, but we'd like to be able to check this before then.  */
-      if (COMPLETE_TYPE_P (complete_type (type)) && is_empty_class (type))
+      if (COMPLETE_TYPE_P (type) && is_empty_class (type))
        return true;
 
       for (binfo = TYPE_BINFO (type), i = 0;
index a65b817af88e9b8eed0f87a8047658e67ba60b62..20c870eafbd2caa5130b022dbc2bdec23ed3462d 100644 (file)
@@ -3699,7 +3699,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
         CONST_DECL for aggregate constants.  */
       if (lval)
        return t;
-      if (is_really_empty_class (TREE_TYPE (t)))
+      if (COMPLETE_TYPE_P (TREE_TYPE (t))
+         && is_really_empty_class (TREE_TYPE (t)))
        {
          /* If the class is empty, we aren't actually loading anything.  */
          r = build_constructor (TREE_TYPE (t), NULL);
diff --git a/gcc/testsuite/g++.dg/template/incomplete7.C b/gcc/testsuite/g++.dg/template/incomplete7.C
new file mode 100644 (file)
index 0000000..80b3e7b
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/72849
+
+extern struct Foo a;
+template <typename> void fn1() { a; }