re PR c++/41131 (non-lvalue in unary `&' wrongly accepted)
authorJakub Jelinek <jakub@redhat.com>
Fri, 21 Aug 2009 07:08:15 +0000 (09:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 21 Aug 2009 07:08:15 +0000 (09:08 +0200)
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.

From-SVN: r150985

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/unary3.C [new file with mode: 0644]

index 7112a67..545ac18 100644 (file)
@@ -1,3 +1,9 @@
+2009-08-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/41131
+       * tree.c (lvalue_p_1) <case CONST_DECL>: Return clk_none if
+       not TREE_STATIC.
+
 2009-08-19  Jason Merrill  <jason@redhat.com>
 
        PR c++/41119
index 1a406a3..f09b036 100644 (file)
@@ -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)
index 585f2f0..80b9cd8 100644 (file)
@@ -1,3 +1,8 @@
+2009-08-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/41131
+       * g++.dg/expr/unary3.C: New test.
+
 2009-08-21  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        * 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 (file)
index 0000000..abca032
--- /dev/null
@@ -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" }
+}