From: Marek Polacek Date: Fri, 23 Mar 2018 12:55:55 +0000 (+0000) Subject: re PR c++/85033 (internal compiler error: in fold_offsetof_1, at c-family/c-common... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b01556f72abfae2c7644a0fb331fedacf7930ff2;p=gcc.git 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 --- 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" }