]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/64487 (internal compiler error: in fold_offsetof_1, at c-family/c-common...
authorJason Merrill <jason@redhat.com>
Tue, 13 Jan 2015 14:49:17 +0000 (09:49 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 13 Jan 2015 14:49:17 +0000 (09:49 -0500)
PR c++/64487
* semantics.c (finish_offsetof): Handle templates here.
* parser.c (cp_parser_builtin_offsetof): Not here.

From-SVN: r219536

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/g++.dg/template/offsetof3.C [new file with mode: 0644]

index ff3162839f7d9f1d55e34112b4d07169dd00e8da..9239750e4723ec68c7d2cf6ce23490b06f6f2e7a 100644 (file)
@@ -1,5 +1,9 @@
 2015-01-13  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++/64251
        * decl2.c (mark_used): Don't mark if in_template_function.
 
index a84bc59cef2273de8d045468858f3382e84fdac5..6d8bef430270f07bf4fa16b832fab2489c9660f4 100644 (file)
@@ -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;
index 30ec7fcf56539f1376ff479c3882c91fd236e472..329f12f09004a8db1f9fef175a9fe3894bf7c202 100644 (file)
@@ -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 %<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 (file)
index 0000000..b173746
--- /dev/null
@@ -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() { }