re PR c++/81054 (ICE with volatile variable in constexpr function)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 17 Jan 2018 20:28:47 +0000 (20:28 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 17 Jan 2018 20:28:47 +0000 (20:28 +0000)
/cp
2018-01-17  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/81054
* constexpr.c (ensure_literal_type_for_constexpr_object): Return
error_mark_node when we give an error.
* decl.c (cp_finish_decl): Use the latter.

/testsuite
2018-01-17  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/81054
* g++.dg/cpp0x/constexpr-ice19.C: New.

From-SVN: r256816

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C [new file with mode: 0644]

index 71fa358f5f8cddb40d5bb2b0e4067f73fc0b025a..17b41921db93e66e6fb050ea4fdf99dc16b02f51 100644 (file)
@@ -1,3 +1,10 @@
+2018-01-17  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/81054
+       * constexpr.c (ensure_literal_type_for_constexpr_object): Return
+       error_mark_node when we give an error.
+       * decl.c (cp_finish_decl): Use the latter.
+
 2018-01-17  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/83287
index b216e090b45386d961f5303a35dd04a01d320f7f..8984613aa4169ecb41385b0a91cbdae4cbf407e3 100644 (file)
@@ -75,7 +75,8 @@ literal_type_p (tree t)
 }
 
 /* If DECL is a variable declared `constexpr', require its type
-   be literal.  Return the DECL if OK, otherwise NULL.  */
+   be literal.  Return error_mark_node if we give an error, the
+   DECL otherwise.  */
 
 tree
 ensure_literal_type_for_constexpr_object (tree decl)
@@ -97,6 +98,7 @@ ensure_literal_type_for_constexpr_object (tree decl)
              error ("the type %qT of %<constexpr%> variable %qD "
                     "is not literal", type, decl);
              explain_non_literal_class (type);
+             decl = error_mark_node;
            }
          else
            {
@@ -105,10 +107,10 @@ ensure_literal_type_for_constexpr_object (tree decl)
                  error ("variable %qD of non-literal type %qT in %<constexpr%> "
                         "function", decl, type);
                  explain_non_literal_class (type);
+                 decl = error_mark_node;
                }
              cp_function_chain->invalid_constexpr = true;
            }
-         return NULL;
        }
     }
   return decl;
index ee469d35137001733be648262c96a93590b1767b..148afa6c9ace158ae5ded668460c9c9520c8c26b 100644 (file)
@@ -6810,8 +6810,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
     }
 
-  if (!ensure_literal_type_for_constexpr_object (decl))
-    DECL_DECLARED_CONSTEXPR_P (decl) = 0;
+  if (ensure_literal_type_for_constexpr_object (decl)
+      == error_mark_node)
+    {
+      DECL_DECLARED_CONSTEXPR_P (decl) = 0;
+      return;
+    }
 
   if (VAR_P (decl)
       && DECL_CLASS_SCOPE_P (decl)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C
new file mode 100644 (file)
index 0000000..7066eab
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/81054
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  volatile int i;
+  constexpr A() : i() {}
+};
+
+struct B
+{
+  static constexpr A a {};  // { dg-error "not literal" }
+};