From 4b8c1a924a55851b83b26391e1703bd15c1c4066 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 21 Aug 2009 09:08:15 +0200 Subject: [PATCH] re PR c++/41131 (non-lvalue in unary `&' wrongly accepted) PR c++/41131 * tree.c (lvalue_p_1) : Return clk_none if not TREE_STATIC. * g++.dg/expr/unary3.C: New test. From-SVN: r150985 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/tree.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/expr/unary3.C | 11 +++++++++++ 4 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/g++.dg/expr/unary3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7112a67..545ac18 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-08-21 Jakub Jelinek + + PR c++/41131 + * tree.c (lvalue_p_1) : Return clk_none if + not TREE_STATIC. + 2009-08-19 Jason Merrill PR c++/41119 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 1a406a3..f09b036 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -132,6 +132,12 @@ lvalue_p_1 (const_tree ref) return clk_ordinary; case CONST_DECL: + /* CONST_DECL without TREE_STATIC are enumeration values and + thus not lvalues. With TREE_STATIC they are used by ObjC++ + in objc_build_string_object and need to be considered as + lvalues. */ + if (! TREE_STATIC (ref)) + return clk_none; case VAR_DECL: if (TREE_READONLY (ref) && ! TREE_STATIC (ref) && DECL_LANG_SPECIFIC (ref) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 585f2f0..80b9cd8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-08-21 Jakub Jelinek + + PR c++/41131 + * g++.dg/expr/unary3.C: New test. + 2009-08-21 Kaz Kojima * gfortran.dg/common_5.f: Add -mdalign for sh. diff --git a/gcc/testsuite/g++.dg/expr/unary3.C b/gcc/testsuite/g++.dg/expr/unary3.C new file mode 100644 index 0000000..abca032 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/unary3.C @@ -0,0 +1,11 @@ +// PR c++/41131 +// { dg-do compile } + +struct X { enum E { a = 100 }; }; + +int +main () +{ + X x; + (void) &x.a; // { dg-error "lvalue required" } +} -- 2.7.4