This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/49085 (ICE with offsetof in template)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 01 Jul 2011 09:35:51 -0400
- Subject: C++ PATCH for c++/49085 (ICE with offsetof in template)
We can't take the offsetof a field until after we've laid out the class.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 92f52fccaaf25b5791c0f8bff930fe75d25bd90b
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jun 30 23:05:49 2011 -0400
PR c++/49085
* semantics.c (finish_offsetof): Complain about incomplete type.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index ad68a01..a704aa3 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3422,6 +3422,12 @@ finish_offsetof (tree expr)
}
if (REFERENCE_REF_P (expr))
expr = TREE_OPERAND (expr, 0);
+ if (TREE_CODE (expr) == COMPONENT_REF)
+ {
+ tree object = TREE_OPERAND (expr, 0);
+ if (!complete_type_or_else (TREE_TYPE (object), object))
+ return error_mark_node;
+ }
return fold_offsetof (expr, NULL_TREE);
}
diff --git a/gcc/testsuite/g++.dg/template/offsetof2.C b/gcc/testsuite/g++.dg/template/offsetof2.C
new file mode 100644
index 0000000..da888f7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/offsetof2.C
@@ -0,0 +1,10 @@
+// PR c++/49085
+
+template <class T>
+struct A // { dg-error "declaration" }
+{
+ int i, j;
+ int ar[__builtin_offsetof(A,j)]; // { dg-error "incomplete type" }
+};
+
+A<int> a;