Skip to content

Commit 465749f

Browse files
author
mpolacek
committed
PR c++/85033
* 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
1 parent 69f5f49 commit 465749f

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

gcc/cp/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-03-23 Marek Polacek <[email protected]>
2+
3+
PR c++/85033
4+
* semantics.c (finish_offsetof): Don't allow CONST_DECLs.
5+
16
2018-03-23 Alexandre Oliva <[email protected]>
27

38
PR c++/71251

gcc/cp/semantics.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,6 +4072,11 @@ finish_offsetof (tree object_ptr, tree expr, location_t loc)
40724072
}
40734073
return error_mark_node;
40744074
}
4075+
if (TREE_CODE (expr) == CONST_DECL)
4076+
{
4077+
error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
4078+
return error_mark_node;
4079+
}
40754080
if (REFERENCE_REF_P (expr))
40764081
expr = TREE_OPERAND (expr, 0);
40774082
if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))

gcc/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-03-23 Marek Polacek <[email protected]>
2+
3+
PR c++/85033
4+
* g++.dg/ext/builtin-offsetof2.C: New test.
5+
16
2018-03-23 Eric Botcazou <[email protected]>
27

38
PR debug/85020
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// PR c++/85033
2+
3+
struct S {
4+
enum { E };
5+
};
6+
7+
int b = __builtin_offsetof(S, E); // { dg-error "cannot apply .offsetof. to an enumerator" }

0 commit comments

Comments
 (0)