aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-03-26 20:38:54 -0400
committerJason Merrill <jason@redhat.com>2022-03-28 09:35:58 -0400
commit72bdfcb848327020f62f72405d72cf85650666e1 (patch)
tree3b9160419fec1da6e98049581f2e546a651430d3 /gcc
parent71e1db540c01a13b01fae054c92878a79252b471 (diff)
downloadgcc-72bdfcb848327020f62f72405d72cf85650666e1.zip
gcc-72bdfcb848327020f62f72405d72cf85650666e1.tar.gz
gcc-72bdfcb848327020f62f72405d72cf85650666e1.tar.bz2
c++: missing aggregate base ctor [PR102045]
When make_base_init_ok changes a call to a complete constructor into a call to a base constructor, we were never marking the base ctor as used, so it didn't get emitted. PR c++/102045 gcc/cp/ChangeLog: * call.cc (make_base_init_ok): Call make_used. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/aggr-base12.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/call.cc1
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/aggr-base12.C24
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index dfe370d..73fede5 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -8958,6 +8958,7 @@ make_base_init_ok (tree exp)
call target. It would be possible to splice in the appropriate
arguments, but probably not worth the complexity. */
return false;
+ mark_used (fn);
AGGR_INIT_EXPR_FN (exp) = build_address (fn);
return true;
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/aggr-base12.C b/gcc/testsuite/g++.dg/cpp1z/aggr-base12.C
new file mode 100644
index 0000000..6f5a6b2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/aggr-base12.C
@@ -0,0 +1,24 @@
+// PR c++/102045
+// { dg-do link { target c++17 } }
+
+template<typename T>
+struct span
+{
+ template<unsigned long N>
+ constexpr span(T (&a)[N]) : data(a), len(N) { }
+ constexpr bool empty() const { return len == 0; }
+ T* data;
+ unsigned long len;
+};
+
+struct byte_writer: span<char> {
+ constexpr void do_something() noexcept {
+ (void)this->empty();
+ }
+};
+
+int main() {
+ char array[1];
+ auto writer = byte_writer{array};
+ writer.do_something();
+}