From 6b11d2e3dfe6f242480e12716dd0c205e6c31c64 Mon Sep 17 00:00:00 2001
From: reichelt <reichelt@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sun, 4 Jun 2006 23:42:04 +0000
Subject: [PATCH] 	PR c++/27601 	* c-common.c (fold_offsetof_1): Handle
 static members.

	* g++.dg/ext/offsetof1.C: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114369 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                        | 5 +++++
 gcc/c-common.c                       | 4 ++++
 gcc/testsuite/ChangeLog              | 5 +++++
 gcc/testsuite/g++.dg/ext/offsetof1.C | 9 +++++++++
 4 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/offsetof1.C

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 96f9cea27390..80f588d15beb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2006-06-04  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+	PR c++/27601
+	* c-common.c (fold_offsetof_1): Handle static members.
+
 2006-06-04 Eric Christopher <echristo@apple.com>
 
 	* stor-layout.c (start_record_layout): Initialize remaining_in_alignment.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index dea83894e7f2..1fb5a6a4a4b8 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -5981,6 +5981,10 @@ fold_offsetof_1 (tree expr)
     case ERROR_MARK:
       return expr;
 
+    case VAR_DECL:
+      error ("cannot apply %<offsetof%> to static data member %qD", expr);
+      return error_mark_node;
+
     case INDIRECT_REF:
       return size_zero_node;
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 43d0d6624af2..9b484a9a363f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-06-04  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+	PR c++/27601
+	* g++.dg/ext/offsetof1.C: New test.
+
 2006-06-04 Eric Christopher <echristo@apple.com>
 
 	* gcc.dg/attr-ms_struct-1.c: New.
diff --git a/gcc/testsuite/g++.dg/ext/offsetof1.C b/gcc/testsuite/g++.dg/ext/offsetof1.C
new file mode 100644
index 000000000000..5d6552f78787
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/offsetof1.C
@@ -0,0 +1,9 @@
+// PR c++/27601
+// Origin: Patrik Hägglund  <patrik.hagglund@bredband.net>
+// { dg-do compile }
+
+struct bar {
+  static int foo;
+};
+
+int a = __builtin_offsetof(bar, foo);  // { dg-error "static data member" }
-- 
GitLab