diff options
author | Jason Merrill <jason@redhat.com> | 2015-01-06 15:44:46 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2015-01-06 15:44:46 -0500 |
commit | b433d944ab6d308ea3f85c7537e64b99bc27bed5 (patch) | |
tree | c7a26affddc60bf802ff92d9266270bfd9436b70 /gcc | |
parent | 47867b4f6556aab84701452eb0ff5a9bd2f46522 (diff) | |
download | gcc-b433d944ab6d308ea3f85c7537e64b99bc27bed5.zip gcc-b433d944ab6d308ea3f85c7537e64b99bc27bed5.tar.gz gcc-b433d944ab6d308ea3f85c7537e64b99bc27bed5.tar.bz2 |
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: r219267
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/parser.c | 10 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/offsetof3.C | 18 |
4 files changed, 32 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 67fd501..604b518 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-01-06 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++/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 52234de..22dff06 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 551bad1..4365a53 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 %<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 0000000..b173746 --- /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() { } |