]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/85033
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 23 Mar 2018 12:55:55 +0000 (12:55 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 23 Mar 2018 12:55:55 +0000 (12:55 +0000)
* semantics.c (finish_offsetof): Don't allow CONST_DECLs.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258801 138bc75d-0d04-0410-961f-82ee72b054a4

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

index cdbbd4193408ece03a15720d1b8177a6d1401554..b7e2846c4b1fc7d08ab3f233c73086ad23f7d813 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 97fa57ae94e54b12faec1e984ba46ac73e127e46..035e3951574894ead12719b0d3054de031512879 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 81c93b4c802682a40ea22ab98acf3c1248c4f92f..88abac8faeb57856c19d87b0971ca23e3d91eb17 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" }