aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-07-31 14:23:10 -0400
committerJason Merrill <jason@redhat.com>2025-07-31 14:23:10 -0400
commitf6462f664725844faa97ae7e8690e4fedee65788 (patch)
tree31b7f8f6c8c867861ddcb540e6e9cbee40f3ce0f /gcc
parentd3828e64a888866c39131fd9feab5d0ee2bd90cf (diff)
downloadgcc-f6462f664725844faa97ae7e8690e4fedee65788.zip
gcc-f6462f664725844faa97ae7e8690e4fedee65788.tar.gz
gcc-f6462f664725844faa97ae7e8690e4fedee65788.tar.bz2
c++: constexpr, array, private ctor [PR120800]
Here cxx_eval_vec_init_1 wants to recreate the default constructor call that we previously built and threw away in build_vec_init_elt, but we aren't in the same access context at this point. Since we already checked access, let's just suppress access control here. Redoing overload resolution at constant evaluation time is sketchy, but should usually be fine for a default/copy constructor. PR c++/120800 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_vec_init_1): Suppress access control. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-array30.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/constexpr.cc3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-array30.C22
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index e051a50..be24ae2 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -6598,6 +6598,9 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
return cxx_eval_bare_aggregate (ctx, init, lval,
non_constant_p, overflow_p, jump_target);
+ /* We already checked access when building the VEC_INIT_EXPR. */
+ deferring_access_check_sentinel acs (dk_deferred);
+
/* For the default constructor, build up a call to the default
constructor of the element type. We only need to handle class types
here, as for a constructor to be constexpr, all members must be
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array30.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array30.C
new file mode 100644
index 0000000..3f72407
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array30.C
@@ -0,0 +1,22 @@
+// PR c++/120800
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+struct Container
+{
+ T m_data[1] {};
+};
+
+class Element
+{
+private:
+ Element() = default;
+
+private:
+ bool m_bool1 { false };
+ bool m_bool2;
+
+ friend struct Container<Element>;
+};
+
+Container<Element> element;