Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
reflect_constant_{array,string} currently fail to pass REFLECT_OBJECT
when creating their resulting reflection. That means the resulting
_ZTAX VAR_DECL is wrongly considered a variable (cf. [basic.pre]/7
and CWG 2983). As a consequence has_identifier etc. behaved incorrectly
on the result of reflect_constant_{array,string}.
PR c++/128425
gcc/cp/ChangeLog:
* reflect.cc (eval_reflect_constant_string): Pass REFLECT_OBJECT
to get_reflection_raw.
(eval_reflect_constant_array): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/constant_of7.C: Adjust the expected result of
is_object. Remove a stale comment.
* g++.dg/reflect/reflect_constant_array1.C: Adjust the expected
result of is_variable. Test is_object. Uncomment a test.
* g++.dg/reflect/reflect_constant_string1.C: Adjust the expected
result of is_variable. Test is_object.
* g++.dg/reflect/has_identifier4.C: New test.
* g++.dg/reflect/reflect_constant_array12.C: New test.
* g++.dg/reflect/reflect_constant_string3.C: New test.
---
gcc/cp/reflect.cc | 4 +-
gcc/testsuite/g++.dg/reflect/constant_of7.C | 7 ++--
.../g++.dg/reflect/has_identifier4.C | 11 ++++++
.../g++.dg/reflect/reflect_constant_array1.C | 20 +++++-----
.../g++.dg/reflect/reflect_constant_array12.C | 38 +++++++++++++++++++
.../g++.dg/reflect/reflect_constant_string1.C | 16 ++++----
.../g++.dg/reflect/reflect_constant_string3.C | 12 ++++++
7 files changed, 84 insertions(+), 24 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/reflect/has_identifier4.C
create mode 100644 gcc/testsuite/g++.dg/reflect/reflect_constant_array12.C
create mode 100644 gcc/testsuite/g++.dg/reflect/reflect_constant_string3.C
diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 4137fb64e75..b9037923b24 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -6613,7 +6613,7 @@ eval_reflect_constant_string (location_t loc, const
constexpr_ctx *ctx,
tree decl = get_template_parm_object (str,
mangle_template_parm_object (str));
DECL_MERGEABLE (decl) = 1;
- return get_reflection_raw (loc, decl);
+ return get_reflection_raw (loc, decl, REFLECT_OBJECT);
}
/* Implement std::meta::reflect_constant_array.
@@ -6642,7 +6642,7 @@ eval_reflect_constant_array (location_t loc, const
constexpr_ctx *ctx,
tree decl = get_template_parm_object (str,
mangle_template_parm_object (str));
DECL_MERGEABLE (decl) = 1;
- return get_reflection_raw (loc, decl);
+ return get_reflection_raw (loc, decl, REFLECT_OBJECT);
}
/* Return CURRENT-SCOPE(P). */
diff --git a/gcc/testsuite/g++.dg/reflect/constant_of7.C
b/gcc/testsuite/g++.dg/reflect/constant_of7.C
index 1958fdcff6a..0035b52d6f9 100644
--- a/gcc/testsuite/g++.dg/reflect/constant_of7.C
+++ b/gcc/testsuite/g++.dg/reflect/constant_of7.C
@@ -8,7 +8,7 @@ using namespace std::meta;
constexpr int arr[] = { 1, 2, 3, 4 };
constexpr auto r = constant_of (^^arr);
-static_assert (!is_value (r) && !is_object (r));
+static_assert (!is_value (r) && is_object (r));
static_assert (*[:r:] == 1);
static_assert ([:r:][0] == 1);
static_assert ([:r:][1] == 2);
@@ -25,12 +25,11 @@ static_assert ([:q:][3] == 4);
using U = int;
constexpr U arr2[] = { 5, 6, 7, 8 };
constexpr auto r2 = constant_of (^^arr2);
-static_assert (!is_value (r2) && !is_object (r2));
+static_assert (!is_value (r2) && is_object (r2));
static_assert ([:r2:][0] == 5);
static_assert ([:r2:][1] == 6);
static_assert ([:r2:][2] == 7);
static_assert ([:r2:][3] == 8);
-// ??? Probably should be const int *.
static_assert (type_of (r2) == ^^const U [4]);
constexpr auto q2 = reflect_constant ([: ^^arr2 :]);
static_assert (type_of (q2) == ^^const U *);
@@ -42,7 +41,7 @@ static_assert ([:q2:][3] == 8);
struct S { int m; };
constexpr S arr3[] = { S{1}, S{2}, S{3} };
constexpr auto r3 = constant_of (^^arr3);
-static_assert (!is_value (r3) && !is_object (r3));
+static_assert (!is_value (r3) && is_object (r3));
static_assert ([:r3:][0].m == 1);
static_assert ([:r3:][1].m == 2);
static_assert ([:r3:][2].m == 3);
diff --git a/gcc/testsuite/g++.dg/reflect/has_identifier4.C
b/gcc/testsuite/g++.dg/reflect/has_identifier4.C
new file mode 100644
index 00000000000..cac99d88ea0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/has_identifier4.C
@@ -0,0 +1,11 @@
+// PR c++/128425
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+using T = int[];
+static_assert(not has_identifier(std::meta::reflect_constant_array(T{0})));
+
+struct S { int m; };
+static_assert(not has_identifier(std::meta::reflect_constant(S{0})));
diff --git a/gcc/testsuite/g++.dg/reflect/reflect_constant_array1.C
b/gcc/testsuite/g++.dg/reflect/reflect_constant_array1.C
index 1d95891355d..b832273c2d2 100644
--- a/gcc/testsuite/g++.dg/reflect/reflect_constant_array1.C
+++ b/gcc/testsuite/g++.dg/reflect/reflect_constant_array1.C
@@ -31,16 +31,16 @@ static_assert (f == reflect_constant_array (std::vector
<int> { 1, 2, 3, 4, 5, 6
static_assert (d != f);
static_assert (g == reflect_constant_array (std::array { 2, 3, 4, 5 }));
static_assert (h == reflect_constant_array (std::vector <int> { 5, 4, 3, 2 }));
-//static_assert (i == reflect_constant_array (std::vector <V> { V { 1, 2, 3 },
V { 2, 3, 4 }, V { 3, 4, 5 } }));
-static_assert (is_variable (a));
-static_assert (is_variable (b));
-static_assert (is_variable (c));
-static_assert (is_variable (d));
-static_assert (is_variable (e));
-static_assert (is_variable (f));
-static_assert (is_variable (g));
-static_assert (is_variable (h));
-static_assert (is_variable (i));
+static_assert (i == reflect_constant_array (std::vector <V> { V { 1, 2, 3 }, V
{ 2, 3, 4 }, V { 3, 4, 5 } }));
+static_assert (!is_variable (a) && is_object (a));
+static_assert (!is_variable (b) && is_object (b));
+static_assert (!is_variable (c) && is_object (c));
+static_assert (!is_variable (d) && is_object (d));
+static_assert (!is_variable (e) && is_object (e));
+static_assert (!is_variable (f) && is_object (f));
+static_assert (!is_variable (g) && is_object (g));
+static_assert (!is_variable (h) && is_object (h));
+static_assert (!is_variable (i) && is_object (i));
static_assert (type_of (a) == ^^const char [5]);
static_assert (type_of (b) == ^^const char32_t [9]);
static_assert (type_of (c) == ^^const std::array <char, 0>);
diff --git a/gcc/testsuite/g++.dg/reflect/reflect_constant_array12.C
b/gcc/testsuite/g++.dg/reflect/reflect_constant_array12.C
new file mode 100644
index 00000000000..42e3e6e4380
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/reflect_constant_array12.C
@@ -0,0 +1,38 @@
+// PR c++/128425
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+using T = int[];
+
+constexpr auto r = std::meta::reflect_constant_array (T{0});
+static_assert (is_object (r));
+static_assert (!is_variable (r));
+static_assert (!has_identifier (r));
+static_assert (has_static_storage_duration (r));
+static_assert (!has_linkage (r));
+static_assert (!has_internal_linkage (r));
+static_assert (!has_external_linkage (r));
+static_assert (!has_module_linkage (r));
+static_assert (!has_c_language_linkage (r));
+static_assert (object_of (r) == r);
+static_assert (type_of (r) == ^^const int[1]);
+
+struct S { int m; };
+template<S s>
+constexpr auto r2 = std::meta::reflect_constant (s);
+static_assert (is_object (r2<S{1}>));
+static_assert (!is_variable (r2<S{1}>));
+static_assert (!has_identifier (r2<S{1}>));
+static_assert (has_static_storage_duration (r2<S{1}>));
+static_assert (!has_linkage (r2<S{1}>));
+static_assert (!has_internal_linkage (r2<S{1}>));
+static_assert (!has_external_linkage (r2<S{1}>));
+static_assert (!has_module_linkage (r2<S{1}>));
+static_assert (!has_c_language_linkage (r2<S{1}>));
+static_assert (object_of (r2<S{1}>) == r2<S{1}>);
+static_assert (type_of (r2<S{1}>) == ^^const S);
+
+template<S> struct X { };
+static_assert (r2<S{1}> == template_arguments_of (^^X<S{1}>)[0]);
diff --git a/gcc/testsuite/g++.dg/reflect/reflect_constant_string1.C
b/gcc/testsuite/g++.dg/reflect/reflect_constant_string1.C
index 92656e9b615..453b78e1bfb 100644
--- a/gcc/testsuite/g++.dg/reflect/reflect_constant_string1.C
+++ b/gcc/testsuite/g++.dg/reflect/reflect_constant_string1.C
@@ -54,14 +54,14 @@ static_assert (o == reflect_constant_string (u8"olle"));
static_assert (p == reflect_constant_string (L"World"));
static_assert (q == reflect_constant_string (u"extremely long string with
non-ASCII characters \N{LATIN SMALL LETTER A WITH ACUTE}"));
static_assert (reflect_constant_string ("bar") != reflect_constant_string
("baz"));
-static_assert (is_variable (a));
-static_assert (is_variable (b));
-static_assert (is_variable (c));
-static_assert (is_variable (d));
-static_assert (is_variable (e));
-static_assert (is_variable (f));
-static_assert (is_variable (g));
-static_assert (is_variable (h));
+static_assert (!is_variable (a) && is_object (a));
+static_assert (!is_variable (b) && is_object (b));
+static_assert (!is_variable (c) && is_object (c));
+static_assert (!is_variable (d) && is_object (d));
+static_assert (!is_variable (e) && is_object (e));
+static_assert (!is_variable (f) && is_object (f));
+static_assert (!is_variable (g) && is_object (g));
+static_assert (!is_variable (h) && is_object (h));
static_assert (type_of (a) == ^^const char [5]);
static_assert (type_of (b) == ^^const char8_t [sizeof u8"abcd\N{LATIN SMALL
LETTER AE}"]);
static_assert (type_of (c) == ^^const wchar_t [5]);
diff --git a/gcc/testsuite/g++.dg/reflect/reflect_constant_string3.C
b/gcc/testsuite/g++.dg/reflect/reflect_constant_string3.C
new file mode 100644
index 00000000000..b0657f73dad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/reflect_constant_string3.C
@@ -0,0 +1,12 @@
+// PR c++/128425
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+constexpr auto r = std::meta::reflect_constant_string ("abcd");
+static_assert (is_object (r));
+static_assert (!is_variable (r));
+static_assert (!has_identifier (r));
+static_assert (object_of (r) == r);
+static_assert (type_of (r) == ^^const char[5]);
base-commit: 9f485bb6ac443e89e25e67069ace874a1c99d9c0
--
2.56.1