Hi,

this issue manifests itself as an ICE on the gcc_assert toward the end of start_decl:

  if (VAR_P (decl)
&& DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
      && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl))
    {
      /* This is a const variable with implicit 'static'.  Set
     DECL_THIS_STATIC so we can tell it from variables that are
     !TREE_PUBLIC because of the anonymous namespace.  */
      gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
      DECL_THIS_STATIC (decl) = 1;
    }

and the reason seems clear to me: both handle_noreturn_attribute and handle_const_attribute call build_pointer_type and discard the TYPE_QUALS on the original POINTER_TYPE. That seems obviously incorrect. The below fixes the ICE and passes testing.

Thanks!
Paolo.

/////////////////
/c-family
2014-06-28  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51400
        * c-common.c (handle_noreturn_attribute, handle_const_attribute):
        Do not discard TYPE_QUALS of type.

/testsuite
2014-06-28  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51400
        * g++.dg/cpp0x/constexpr-attribute3.C: New.
Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c (revision 212104)
+++ c-family/c-common.c (working copy)
@@ -6575,9 +6575,11 @@ handle_noreturn_attribute (tree *node, tree name,
   else if (TREE_CODE (type) == POINTER_TYPE
           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     TREE_TYPE (*node)
-      = build_pointer_type
-       (build_type_variant (TREE_TYPE (type),
-                            TYPE_READONLY (TREE_TYPE (type)), 1));
+      = (build_qualified_type
+        (build_pointer_type
+         (build_type_variant (TREE_TYPE (type),
+                              TYPE_READONLY (TREE_TYPE (type)), 1)),
+         TYPE_QUALS (type)));
   else
     {
       warning (OPT_Wattributes, "%qE attribute ignored", name);
@@ -6988,9 +6990,11 @@ handle_const_attribute (tree *node, tree name, tre
   else if (TREE_CODE (type) == POINTER_TYPE
           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     TREE_TYPE (*node)
-      = build_pointer_type
-       (build_type_variant (TREE_TYPE (type), 1,
-                            TREE_THIS_VOLATILE (TREE_TYPE (type))));
+      = (build_qualified_type
+        (build_pointer_type
+         (build_type_variant (TREE_TYPE (type), 1,
+                              TREE_THIS_VOLATILE (TREE_TYPE (type)))),
+         TYPE_QUALS (type)));
   else
     {
       warning (OPT_Wattributes, "%qE attribute ignored", name);
Index: testsuite/g++.dg/cpp0x/constexpr-attribute3.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-attribute3.C       (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-attribute3.C       (working copy)
@@ -0,0 +1,5 @@
+// PR c++/51400
+// { dg-do compile { target c++11 } }
+
+constexpr int (*f)() __attribute__((noreturn)) = 0;
+constexpr int (*g)() __attribute__((const)) = 0;

Reply via email to