re PR c++/35741 (ICE with offsetof and references)
authorJakub Jelinek <jakub@redhat.com>
Thu, 3 Apr 2008 07:43:46 +0000 (09:43 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 3 Apr 2008 07:43:46 +0000 (09:43 +0200)
PR c++/35741
* semantics.c (finish_offsetof): Undo effect of convert_from_reference
before calling fold_offsetof.

* g++.dg/other/offsetof5.C: New test.

From-SVN: r133863

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

index c7600ecb0e2ab14513dc8ad700e3b30e4080fb0f..713b62e6e0af020bdecbb520769691eb574c22c0 100644 (file)
@@ -1,3 +1,9 @@
+2008-04-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/35741
+       * semantics.c (finish_offsetof): Undo effect of convert_from_reference
+       before calling fold_offsetof.
+
 2008-04-03  Tom Tromey  <tromey@redhat.com>
 
        * Make-lang.in (c++_OBJS): New variable.
index 8966bf5d9216288594db84a4afb61ebe44a0be82..95ebde69a8dedcf76b19f6f5dcecc71f4e4c9503 100644 (file)
@@ -3039,6 +3039,8 @@ finish_offsetof (tree expr)
       error ("cannot apply %<offsetof%> to member function %qD", expr);
       return error_mark_node;
     }
+  if (TREE_CODE (expr) == INDIRECT_REF && REFERENCE_REF_P (expr))
+    expr = TREE_OPERAND (expr, 0);
   return fold_offsetof (expr, NULL_TREE);
 }
 
index f40f99fa111087394ae9f272e7271f1a2802c70b..e291072c8396a8668adcd9624d5232bddb897425 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/35741
+       * g++.dg/other/offsetof5.C: New test.
+
 2008-04-03  Paolo Bonzini  <bonzini@gnu.org>
 
        PR rtl-optimization/35281
diff --git a/gcc/testsuite/g++.dg/other/offsetof5.C b/gcc/testsuite/g++.dg/other/offsetof5.C
new file mode 100644 (file)
index 0000000..97dd5e9
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/35741
+// { dg-do compile }
+
+#include <stddef.h>
+
+struct A
+{
+  char c;
+  int &i;
+};
+
+int j = offsetof (A, i);               // { dg-warning "invalid access|offsetof" }
+
+template <typename T>
+struct S
+{
+  T h;
+  T &i;
+  static const int j = offsetof (S, i);        // { dg-warning "invalid access|offsetof" }
+};
+
+int k = S<int>::j;                     // { dg-warning "instantiated from here" }