From b01556f72abfae2c7644a0fb331fedacf7930ff2 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 23 Mar 2018 12:55:55 +0000 Subject: [PATCH] re PR c++/85033 (internal compiler error: in fold_offsetof_1, at c-family/c-common.c:6269) 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 | 5 +++++ gcc/cp/semantics.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/builtin-offsetof2.C | 7 +++++++ 4 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/builtin-offsetof2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cdbbd419340..b7e2846c4b1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-03-23 Marek Polacek + + PR c++/85033 + * semantics.c (finish_offsetof): Don't allow CONST_DECLs. + 2018-03-23 Alexandre Oliva PR c++/71251 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 97fa57ae94e..035e3951574 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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 % 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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 81c93b4c802..88abac8faeb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-23 Marek Polacek + + PR c++/85033 + * g++.dg/ext/builtin-offsetof2.C: New test. + 2018-03-23 Eric Botcazou 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 index 00000000000..07cc55a65c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin-offsetof2.C @@ -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" } -- 2.30.2