From: Jason Merrill Date: Tue, 13 Jan 2015 14:49:17 +0000 (-0500) Subject: re PR c++/64487 (internal compiler error: in fold_offsetof_1, at c-family/c-common... X-Git-Tag: releases/gcc-4.8.5~329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1dca92f0ebcd0e6c5e64d75e17bc8753047683a;p=thirdparty%2Fgcc.git re PR c++/64487 (internal compiler error: in fold_offsetof_1, at c-family/c-common.c:9857) PR c++/64487 * semantics.c (finish_offsetof): Handle templates here. * parser.c (cp_parser_builtin_offsetof): Not here. From-SVN: r219536 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ff3162839f7d..9239750e4723 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-01-13 Jason Merrill + PR c++/64487 + * semantics.c (finish_offsetof): Handle templates here. + * parser.c (cp_parser_builtin_offsetof): Not here. + PR c++/64251 * decl2.c (mark_used): Don't mark if in_template_function. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a84bc59cef22..6d8bef430270 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8024,12 +8024,7 @@ cp_parser_builtin_offsetof (cp_parser *parser) } success: - /* If we're processing a template, we can't finish the semantics yet. - Otherwise we can fold the entire expression now. */ - if (processing_template_decl) - expr = build1 (OFFSETOF_EXPR, size_type_node, expr); - else - expr = finish_offsetof (expr); + expr = finish_offsetof (expr); failure: parser->integral_constant_expression_p = save_ice_p; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 30ec7fcf5653..329f12f09004 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3651,6 +3651,14 @@ finish_bases (tree type, bool direct) tree finish_offsetof (tree expr) { + /* If we're processing a template, we can't finish the semantics yet. + Otherwise we can fold the entire expression now. */ + if (processing_template_decl) + { + expr = build1 (OFFSETOF_EXPR, size_type_node, expr); + return expr; + } + if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR) { error ("cannot apply % to destructor %<~%T%>", diff --git a/gcc/testsuite/g++.dg/template/offsetof3.C b/gcc/testsuite/g++.dg/template/offsetof3.C new file mode 100644 index 000000000000..b17374645b20 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/offsetof3.C @@ -0,0 +1,18 @@ +// PR c++/64487 + +struct foo { + int member; +}; + +template < int N> +struct bar {}; + +template +struct qux { + static bar static_member; +}; + +template +bar qux::static_member; + +int main() { }