This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix c++/17221
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 31 Aug 2004 10:41:23 -0700
- Subject: fix c++/17221
I had the code in the wrong place for expansion of a template argument.
This does *not* fix Mark's test case.
r~
PR c++/17221
* pt.c (tsubst_expr): Move OFFSETOF_EXPR handling ...
(tsubst_copy_and_build): ... here.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.918
diff -c -p -d -r1.918 pt.c
*** cp/pt.c 30 Aug 2004 16:03:46 -0000 1.918
--- cp/pt.c 31 Aug 2004 17:22:28 -0000
*************** tsubst_expr (tree t, tree args, tsubst_f
*** 8085,8095 ****
tsubst (TREE_TYPE (t), args, complain, NULL_TREE);
break;
- case OFFSETOF_EXPR:
- t = tsubst_copy_and_build (TREE_OPERAND (t, 0), args, complain,
- in_decl, false);
- return fold_offsetof (t);
-
default:
gcc_assert (!STATEMENT_CODE_P (TREE_CODE (t)));
--- 8085,8090 ----
*************** tsubst_copy_and_build (tree t,
*** 8630,8635 ****
--- 8625,8633 ----
tsubst_copy (TREE_TYPE (t), args, complain,
in_decl));
+ case OFFSETOF_EXPR:
+ return fold_offsetof (RECUR (TREE_OPERAND (t, 0)));
+
default:
return tsubst_copy (t, args, complain, in_decl);
}
Index: testsuite/g++.dg/template/offsetof1.C
===================================================================
RCS file: testsuite/g++.dg/template/offsetof1.C
diff -N testsuite/g++.dg/template/offsetof1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/offsetof1.C 31 Aug 2004 17:22:29 -0000
***************
*** 0 ****
--- 1,16 ----
+ // { dg-do compile }
+ // PR c++/17221
+
+ #include <cstddef>
+
+ template <int N> struct Bar;
+ template <> struct Bar<3> {};
+
+ template <class T>
+ struct Foo {
+ Bar<offsetof(T, a) + 3> k;
+ };
+
+ struct A { int a; };
+
+ template struct Foo<A>;