OSDN Git Service

PR c++/17221
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 31 Aug 2004 17:39:56 +0000 (17:39 +0000)
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 31 Aug 2004 17:39:56 +0000 (17:39 +0000)
        * pt.c (tsubst_expr): Move OFFSETOF_EXPR handling ...
        (tsubst_copy_and_build): ... here.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@86835 138bc75d-0d04-0410-961f-82ee72b054a4

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

index eea871b..2aaca7d 100644 (file)
@@ -1,3 +1,9 @@
+2004-08-31  Richard Henderson  <rth@redhat.com>
+
+       PR c++/17221
+       * pt.c (tsubst_expr): Move OFFSETOF_EXPR handling ...
+       (tsubst_copy_and_build): ... here.
+
 2004-08-30  Mark Mitchell  <mark@codesourcery.com>
 
        * cp-tree.h (initialize_artificial_var): Declare.
index d7335a0..18f15a8 100644 (file)
@@ -8085,11 +8085,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
       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)));
       
@@ -8630,6 +8625,9 @@ tsubst_copy_and_build (tree t,
                             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);
     }
diff --git a/gcc/testsuite/g++.dg/template/offsetof1.C b/gcc/testsuite/g++.dg/template/offsetof1.C
new file mode 100644 (file)
index 0000000..1ee9be1
--- /dev/null
@@ -0,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>;