re PR c++/85033 (internal compiler error: in fold_offsetof_1, at c-family/c-common...
authorMarek Polacek <polacek@redhat.com>
Fri, 23 Mar 2018 12:55:55 +0000 (12:55 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 23 Mar 2018 12:55:55 +0000 (12:55 +0000)
PR c++/85033
* semantics.c (finish_offsetof): Don't allow CONST_DECLs.

* g++.dg/ext/builtin-offsetof2.C: New test.

From-SVN: r258801

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/builtin-offsetof2.C [new file with mode: 0644]

index cdbbd41..b7e2846 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-23  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85033
+       * semantics.c (finish_offsetof): Don't allow CONST_DECLs.
+
 2018-03-23  Alexandre Oliva <aoliva@redhat.com>
 
        PR c++/71251
index 97fa57a..035e395 100644 (file)
@@ -4072,6 +4072,11 @@ finish_offsetof (tree object_ptr, tree expr, location_t loc)
        }
       return error_mark_node;
     }
+  if (TREE_CODE (expr) == CONST_DECL)
+    {
+      error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
+      return error_mark_node;
+    }
   if (REFERENCE_REF_P (expr))
     expr = TREE_OPERAND (expr, 0);
   if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
index 81c93b4..88abac8 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-23  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85033
+       * g++.dg/ext/builtin-offsetof2.C: New test.
+
 2018-03-23  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR debug/85020
diff --git a/gcc/testsuite/g++.dg/ext/builtin-offsetof2.C b/gcc/testsuite/g++.dg/ext/builtin-offsetof2.C
new file mode 100644 (file)
index 0000000..07cc55a
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/85033
+
+struct S {
+  enum { E };
+};
+
+int b = __builtin_offsetof(S, E); // { dg-error "cannot apply .offsetof. to an enumerator" }