offset_map[fip->fields[i].offset] = i;
struct objfile *objfile = cu->per_objfile->objfile;
- gdb::array_view<variant_part> parts
+ gdb::array_view<const variant_part> parts
= create_variant_parts (&objfile->objfile_obstack, offset_map, fip,
fip->variant_parts);
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 (_("\
#include "gdbsupport/selftest.h"
#include "gdbsupport/array-view.h"
#include <array>
+#include <vector>
namespace selftests {
namespace array_view_tests {
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 ()
{
&& !is_convertible <C, array_view<B>> ());
}
+/* Check that there's no container->view conversion for containers of derived
+ types or subclasses. */
+
+template<template<typename ...> typename Container>
+static constexpr bool
+check_ctor_from_container ()
+{
+ using gdb::array_view;
+
+ return ( is_convertible <Container<A>, array_view<A>> ()
+ && !is_convertible <Container<B>, array_view<A>> ()
+ && !is_convertible <Container<C>, array_view<A>> ()
+
+ && !is_convertible <Container<A>, array_view<B>> ()
+ && is_convertible <Container<B>, array_view<B>> ()
+ && !is_convertible <Container<C>, array_view<B>> ());
+}
+
} /* namespace no_slicing */
static_assert (no_slicing::check (), "");
+static_assert (no_slicing::check_ctor_from_container<std::vector> (), "");
+static_assert (no_slicing::check_ctor_from_container<gdb::array_view> (), "");
/* Check that array_view implicitly converts from std::vector. */
template<typename Container,
typename = Requires<gdb::Not<IsDecayedT<Container>>>,
typename
- = Requires<std::is_convertible
- <decltype (std::declval<Container> ().data ()),
- T *>>,
+ = Requires<DecayedConvertible
+ <typename std::remove_pointer
+ <decltype (std::declval<Container> ().data ())
+ >::type>>,
typename
= Requires<std::is_convertible
<decltype (std::declval<Container> ().size ()),