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.
}
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;
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%>",
--- /dev/null
+// 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() { }