This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Don't treat enumeration vals as lvalues (PR c++/41131)


Hi!

When Obj-C++ support was added, CONST_DECL handling has been added to
lvalue_p_1.  As CONST_DECL are used in C++ land just for enumeration values,
I assume it could be only because of objc_build_string_object which creates
a CONST_DECL and creates ADDR_EXPR from it.
The following patch stops treating enumeration values as lvalues again,
just handles the special ObjC CONST_DECL.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.4?

2009-08-20  Jakub Jelinek  <jakub@redhat.com>

	PR c++/41131
	* tree.c (lvalue_p_1) <case CONST_DECL>: Return clk_none if
	not TREE_STATIC.

	* g++.dg/expr/unary3.C: New test.

--- gcc/cp/tree.c.jj	2009-08-19 17:46:00.000000000 +0200
+++ gcc/cp/tree.c	2009-08-20 21:16:00.000000000 +0200
@@ -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)
--- gcc/testsuite/g++.dg/expr/unary3.C.jj	2009-08-20 21:21:18.000000000 +0200
+++ gcc/testsuite/g++.dg/expr/unary3.C	2009-08-20 21:19:32.000000000 +0200
@@ -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" }
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]