Fix constexpr lvalue use of __real and __imag.
authorJason Merrill <jason@redhat.com>
Sun, 13 Nov 2016 06:52:15 +0000 (01:52 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 13 Nov 2016 06:52:15 +0000 (01:52 -0500)
* constexpr.c (potential_constant_expression_1): REALPART_EXPR and
IMAGPART_EXPR can be lvalues.

From-SVN: r242349

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-complex2.C [new file with mode: 0644]

index 60186ee9fb84960d1d4beb2b7fd4a11271584e20..b2195e4b687c7c8f607023026fe80af50663559f 100644 (file)
@@ -1,5 +1,8 @@
 2016-11-12  Jason Merrill  <jason@redhat.com>
 
+       * constexpr.c (potential_constant_expression_1): REALPART_EXPR and
+       IMAGPART_EXPR can be lvalues.
+
        DR 374
        PR c++/56840
        * pt.c (check_specialization_namespace): Allow any enclosing
index f75f0b039fa958635e914fafa903039fd7c6e8e0..739e902cf6a1b239d00eb249e5bb8ff0c1e2bdde 100644 (file)
@@ -5105,6 +5105,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
 #endif
       return RECUR (t, any);
 
+    case REALPART_EXPR:
+    case IMAGPART_EXPR:
     case COMPONENT_REF:
     case BIT_FIELD_REF:
     case ARROW_EXPR:
@@ -5276,8 +5278,6 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
        return true;
       /* fall through.  */
 
-    case REALPART_EXPR:
-    case IMAGPART_EXPR:
     case CONJ_EXPR:
     case SAVE_EXPR:
     case FIX_TRUNC_EXPR:
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-complex2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-complex2.C
new file mode 100644 (file)
index 0000000..9a9291b
--- /dev/null
@@ -0,0 +1,5 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+static _Complex int i;
+static_assert (&__imag i == &__imag i, "");