diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 00856b86483..ed101237587 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -14936,7 +14936,7 @@ add_variant_property (struct field_info *fip, struct type *type, offset_map[fip->fields[i].offset] = i; struct objfile *objfile = cu->per_objfile->objfile; - gdb::array_view parts + gdb::array_view parts = create_variant_parts (&objfile->objfile_obstack, offset_map, fip, fip->variant_parts); diff --git a/gdb/maint.c b/gdb/maint.c index bcc71aab579..e03abfacdae 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -1158,7 +1158,7 @@ maintenance_selftest (const char *args, int from_tty) auto grp = make_maintenance_selftest_option_group (&opts); gdb::option::process_options (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp); - gdb_argv argv (args); + const gdb_argv argv (args); selftests::run_tests (argv.as_array_view (), opts.verbose); #else printf_filtered (_("\ diff --git a/gdb/unittests/array-view-selftests.c b/gdb/unittests/array-view-selftests.c index b62369bc8cd..43b7434d10f 100644 --- a/gdb/unittests/array-view-selftests.c +++ b/gdb/unittests/array-view-selftests.c @@ -21,6 +21,7 @@ #include "gdbsupport/selftest.h" #include "gdbsupport/array-view.h" #include +#include namespace selftests { namespace array_view_tests { @@ -86,8 +87,8 @@ struct A { int i; }; struct B : A { int j; }; struct C : A { int l; }; -/* Check that there's no array->view conversion for arrays of derived - types or subclasses. */ +/* Check that there's no array->view conversion for arrays of derived types or + subclasses. */ static constexpr bool check () { @@ -116,9 +117,29 @@ check () && !is_convertible > ()); } +/* Check that there's no container->view conversion for containers of derived + types or subclasses. */ + +template typename Container> +static constexpr bool +check_ctor_from_container () +{ + using gdb::array_view; + + return ( is_convertible , array_view> () + && !is_convertible , array_view> () + && !is_convertible , array_view> () + + && !is_convertible , array_view> () + && is_convertible , array_view> () + && !is_convertible , array_view> ()); +} + } /* namespace no_slicing */ static_assert (no_slicing::check (), ""); +static_assert (no_slicing::check_ctor_from_container (), ""); +static_assert (no_slicing::check_ctor_from_container (), ""); /* Check that array_view implicitly converts from std::vector. */ diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h index ab1d032c60e..6f7e45a979c 100644 --- a/gdbsupport/array-view.h +++ b/gdbsupport/array-view.h @@ -139,9 +139,10 @@ public: template>>, typename - = Requires ().data ()), - T *>>, + = Requires ().data ()) + >::type>>, typename = Requires ().size ()),