From 60c4d1358ad5e944caeb1a335da0b2703d909670 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 3 Apr 2008 09:43:46 +0200 Subject: [PATCH] re PR c++/35741 (ICE with offsetof and references) 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 | 6 ++++++ gcc/cp/semantics.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/other/offsetof5.C | 22 ++++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/g++.dg/other/offsetof5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c7600ecb0e2..713b62e6e0a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2008-04-03 Jakub Jelinek + + PR c++/35741 + * semantics.c (finish_offsetof): Undo effect of convert_from_reference + before calling fold_offsetof. + 2008-04-03 Tom Tromey * Make-lang.in (c++_OBJS): New variable. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 8966bf5d921..95ebde69a8d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3039,6 +3039,8 @@ finish_offsetof (tree expr) error ("cannot apply % 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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f40f99fa111..e291072c839 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-04-03 Jakub Jelinek + + PR c++/35741 + * g++.dg/other/offsetof5.C: New test. + 2008-04-03 Paolo Bonzini 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 index 00000000000..97dd5e93710 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/offsetof5.C @@ -0,0 +1,22 @@ +// PR c++/35741 +// { dg-do compile } + +#include + +struct A +{ + char c; + int &i; +}; + +int j = offsetof (A, i); // { dg-warning "invalid access|offsetof" } + +template +struct S +{ + T h; + T &i; + static const int j = offsetof (S, i); // { dg-warning "invalid access|offsetof" } +}; + +int k = S::j; // { dg-warning "instantiated from here" } -- 2.30.2