diff options
author | Jason Merrill <jason@redhat.com> | 2015-01-07 15:18:39 +0000 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2015-01-07 15:18:39 +0000 |
commit | 06833bfdb40a5b286e753add8b9e4ce751013165 (patch) | |
tree | e9ba171412fd13617dd3659ac75ab6ad65128ae9 | |
parent | f8e0536caf1c2a6b4ac1a3281ad6f076c95b455a (diff) |
PR c++/64487
* semantics.c (finish_offsetof): Handle templates here.
* parser.c (cp_parser_builtin_offsetof): Not here.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-4_9-branch@219311 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/parser.c | 7 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/offsetof3.C | 18 |
4 files changed, 31 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0d7e2fe8639..8fcbbe65352 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-01-07 Jason Merrill <jason@redhat.com> + PR c++/64487 + * semantics.c (finish_offsetof): Handle templates here. + * parser.c (cp_parser_builtin_offsetof): Not here. + PR c++/64352 * pt.c (tsubst_copy_and_build): Pass complain to mark_used. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7893235afba..93f94d260c1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8479,12 +8479,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 e9635f6a202..bbed56fb06e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3803,6 +3803,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 %<offsetof%> 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 <int N> +struct qux { + static bar<N+__builtin_offsetof(foo,member)> static_member; +}; + +template <int N> +bar<N+__builtin_offsetof(foo,member)> qux<N>::static_member; + +int main() { } |