From fbbb80c79e464f12ee0977190189384b3ab9e429 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 6 Jan 2015 20:44:46 +0000 Subject: [PATCH] PR c++/64487 * semantics.c (finish_offsetof): Handle templates here. * parser.c (cp_parser_builtin_offsetof): Not here. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219267 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/parser.c | 10 +--------- gcc/cp/semantics.c | 9 +++++++++ gcc/testsuite/g++.dg/template/offsetof3.C | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/offsetof3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 67fd50110a2..604b518d607 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-01-06 Jason Merrill + PR c++/64487 + * semantics.c (finish_offsetof): Handle templates here. + * parser.c (cp_parser_builtin_offsetof): Not here. + PR c++/64496 * semantics.c (process_outer_var_ref): Diagnose lambda in local class NSDMI. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 52234de5cd4..22dff06eb6c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8729,15 +8729,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); - SET_EXPR_LOCATION (expr, loc); - } - else - expr = finish_offsetof (expr, loc); + expr = finish_offsetof (expr, loc); failure: parser->integral_constant_expression_p = save_ice_p; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 551bad132e9..4365a53acd6 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3870,6 +3870,15 @@ finish_bases (tree type, bool direct) tree finish_offsetof (tree expr, location_t loc) { + /* 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); + SET_EXPR_LOCATION (expr, loc); + 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 00000000000..b17374645b2 --- /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() { } -- 2.11.4.GIT