Skip to content

Commit

Permalink
Fix debugger visualizer for Ext=gsl::dynamic_extent
Browse files Browse the repository at this point in the history
VS 2019 doesn't seem to match -1 for size_t template parameter, as a result dynamic span/basic_string_span/basic_zstring_span show extent as `extent = 4294967295` (for 32-bit builds). This change updates details::extent_type to have static constexpr size_ parameter for non-dynamic span/basic_string_span/basic_zstring_span and simplifies/removes dynamic versions from GSL.natvis

fixes microsoft#856
  • Loading branch information
pps83 committed May 14, 2020
1 parent 0843ea4 commit bacb9c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 47 deletions.
47 changes: 4 additions & 43 deletions GSL.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
</Expand>
</Type>

<!-- These types are from the span header. -->
<!-- This is for dynamic_extent spans. -->
<Type Name="gsl::span&lt;*, -1&gt;">
<Type Name="gsl::span&lt;*, *&gt;">
<DisplayString>{{ extent = {storage_.size_} }}</DisplayString>
<Expand>
<ArrayItems>
Expand All @@ -31,19 +29,7 @@
</Expand>
</Type>

<!-- This works for constexpr size spans. -->
<Type Name="gsl::span&lt;*, *&gt;">
<DisplayString>{{ extent = {extent} }}</DisplayString>
<Expand>
<ArrayItems>
<Size>extent</Size>
<ValuePointer>storage_.data_</ValuePointer>
</ArrayItems>
</Expand>
</Type>

<!-- This is for dynamic_extent string_spans. -->
<Type Name="gsl::basic_string_span&lt;*, -1&gt;">
<Type Name="gsl::basic_string_span&lt;*, *&gt;">
<DisplayString>{span_.storage_.data_,[span_.storage_.size_]na}</DisplayString>
<Expand>
<Item Name="[size]">span_.storage_.size_</Item>
Expand All @@ -54,20 +40,7 @@
</Expand>
</Type>

<!-- This works for constexpr size string_spans. -->
<Type Name="gsl::basic_string_span&lt;*, *&gt;">
<DisplayString>{span_.storage_.data_,[span_.extent]na}</DisplayString>
<Expand>
<Item Name="[size]">span_.extent</Item>
<ArrayItems>
<Size>span_.extent</Size>
<ValuePointer>span_.storage_.data_</ValuePointer>
</ArrayItems>
</Expand>
</Type>

<!-- This is for dynamic_extent zstring_spans. -->
<Type Name="gsl::basic_zstring_span&lt;*, -1&gt;">
<Type Name="gsl::basic_zstring_span&lt;*, *&gt;">
<DisplayString>{span_.storage_.data_,[span_.storage_.size_]na}</DisplayString>
<Expand>
<Item Name="[size]">span_.storage_.size_</Item>
Expand All @@ -77,19 +50,7 @@
</ArrayItems>
</Expand>
</Type>

<!-- This works for constexpr size string_spans. -->
<Type Name="gsl::basic_zstring_span&lt;*, *&gt;">
<DisplayString>{span_.storage_.data_,[span_.extent]na}</DisplayString>
<Expand>
<Item Name="[size]">span_.extent</Item>
<ArrayItems>
<Size>span_.extent</Size>
<ValuePointer>span_.storage_.data_</ValuePointer>
</ArrayItems>
</Expand>
</Type>


<!-- These types are from the gsl header. -->
<Type Name="gsl::not_null&lt;*&gt;">
<!-- We can always dereference this since it's an invariant. -->
Expand Down
15 changes: 11 additions & 4 deletions include/gsl/span
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,21 @@ namespace details
template <size_type Other>
constexpr extent_type(extent_type<Other> ext)
{
static_assert(Other == Ext,
static_assert(Other == size_,
"Mismatch between fixed-size extent and size of initializing data.");
Expects(ext.size() == Ext);
Expects(ext.size() == size_);
}

constexpr extent_type(size_type size) { Expects(size == Ext); }
constexpr extent_type(size_type size) { Expects(size == size_); }

constexpr size_type size() const noexcept { return Ext; }
constexpr size_type size() const noexcept { return size_; }

private:
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
static constexpr const size_type size_ = Ext; // static size equal to Ext
#else
static constexpr size_type size_ = Ext; // static size equal to Ext
#endif
};

template <>
Expand Down

0 comments on commit bacb9c5

Please sign in to comment.