When looking at constexpr references, I've noticed staticp handles
COMPONENT_REFs and ARRAY_REFs (the latter if the index is INTEGER_CST),
but not {REAL,IMAG}PART_EXPR. I think that is incorrect and causes
rejection of constexpr (for C++) or static const (for C) addresses
of __real__ or __imag__ parts of static vars.
2025-09-09 Jakub Jelinek <jakub@redhat.com>
PR c++/121678
* tree.cc (staticp): Handle REALPART_EXPR and IMAGPART_EXPR.
* g++.dg/ext/pr121678.C: New test.
* gcc.dg/pr121678.c: New test.
--- /dev/null
+// PR c++/121678
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+static constexpr _Complex double a = 1.0;
+static constexpr double *r = &__real__ a;
+static constexpr double *i = &__imag__ a;
--- /dev/null
+/* PR c++/121678 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+static const _Complex double a = 1.0;
+static const double *const r = &__real__ a;
+static const double *const i = &__imag__ a;
else
return NULL;
+ case REALPART_EXPR:
+ case IMAGPART_EXPR:
+ return staticp (TREE_OPERAND (arg, 0));
+
case COMPOUND_LITERAL_EXPR:
return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;