Skip to content

Commit 6ba8ef6

Browse files
committed
refactor(Corpus): valueless_after_move is asserted
Only use MRDOCS_ASSERT for valueless_after_move(). Since polymorphic objects are no longer nullable, and using moved-from objects is invalid, we should never check valueless_after_move() to determine conditional application logic.
1 parent afa558a commit 6ba8ef6

File tree

20 files changed

+189
-236
lines changed

20 files changed

+189
-236
lines changed

include/mrdocs/ADT/Polymorphic.hpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ template <class T> inline constexpr bool IsPolymorphic<Polymorphic<T>> = true;
193193

194194
} // namespace detail
195195

196+
/// @copydoc CompareDerived(Polymorphic<Base> const&, Polymorphic<Base> const&)
197+
template <class Base>
198+
requires(!detail::IsPolymorphic<Base>) && detail::CanVisitCompare<Base>
199+
auto
200+
CompareDerived(Base const& lhs, Base const& rhs)
201+
{
202+
if (lhs.Kind == rhs.Kind)
203+
{
204+
return visit(lhs, detail::VisitCompareFn<Base>(rhs));
205+
}
206+
return lhs.Kind <=> rhs.Kind;
207+
}
208+
196209
/** @brief Compares two polymorphic objects that have visit functions
197210
198211
This function compares two Polymorphic objects that
@@ -217,30 +230,9 @@ requires detail::CanVisitCompare<Base>
217230
auto
218231
CompareDerived(Polymorphic<Base> const& lhs, Polymorphic<Base> const& rhs)
219232
{
220-
if (!lhs.valueless_after_move() && !rhs.valueless_after_move())
221-
{
222-
if (lhs->Kind == rhs->Kind)
223-
{
224-
return visit(*lhs, detail::VisitCompareFn<Base>(*rhs));
225-
}
226-
return lhs->Kind <=> rhs->Kind;
227-
}
228-
return lhs.valueless_after_move() ?
229-
std::strong_ordering::less :
230-
std::strong_ordering::greater;
231-
}
232-
233-
/// @copydoc CompareDerived(Polymorphic<Base> const&, Polymorphic<Base> const&)
234-
template <class Base>
235-
requires(!detail::IsPolymorphic<Base>) && detail::CanVisitCompare<Base>
236-
auto
237-
CompareDerived(Base const& lhs, Base const& rhs)
238-
{
239-
if (lhs.Kind == rhs.Kind)
240-
{
241-
return visit(lhs, detail::VisitCompareFn<Base>(rhs));
242-
}
243-
return lhs.Kind <=> rhs.Kind;
233+
MRDOCS_ASSERT(!lhs.valueless_after_move());
234+
MRDOCS_ASSERT(!rhs.valueless_after_move());
235+
return CompareDerived(*lhs, *rhs);
244236
}
245237

246238
template <class Base>

include/mrdocs/Metadata/Name.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ tag_invoke(
6161
Polymorphic<NameInfo> const& I,
6262
DomCorpus const* domCorpus)
6363
{
64-
if(I.valueless_after_move())
65-
{
66-
v = nullptr;
67-
return;
68-
}
64+
MRDOCS_ASSERT(!I.valueless_after_move());
6965
tag_invoke(dom::ValueFromTag{}, v, *I, domCorpus);
7066
}
7167

include/mrdocs/Metadata/TArg.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ tag_invoke(
6464
Polymorphic<TArg> const& I,
6565
DomCorpus const* domCorpus)
6666
{
67-
if (I.valueless_after_move())
68-
{
69-
v = nullptr;
70-
return;
71-
}
67+
MRDOCS_ASSERT(!I.valueless_after_move());
7268
tag_invoke(dom::ValueFromTag{}, v, *I, domCorpus);
7369
}
7470

include/mrdocs/Metadata/TParam.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ tag_invoke(
7171
Polymorphic<TParam> const& I,
7272
DomCorpus const* domCorpus)
7373
{
74-
if (I.valueless_after_move())
75-
{
76-
v = nullptr;
77-
return;
78-
}
74+
MRDOCS_ASSERT(!I.valueless_after_move());
7975
tag_invoke(dom::ValueFromTag{}, v, *I, domCorpus);
8076
}
8177

include/mrdocs/Metadata/Type.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ tag_invoke(
175175
Polymorphic<TypeInfo> const& I,
176176
DomCorpus const* domCorpus)
177177
{
178-
if (I.valueless_after_move())
179-
{
180-
v = nullptr;
181-
return;
182-
}
178+
MRDOCS_ASSERT(!I.valueless_after_move());
183179
tag_invoke(dom::ValueFromTag{}, v, *I, domCorpus);
184180
}
185181

src/lib/AST/ASTVisitor.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ populate(
714714
// CXXBaseSpecifier::getEllipsisLoc indicates whether the
715715
// base was a pack expansion; a PackExpansionType is not built
716716
// for base-specifiers
717-
if (!BaseType.valueless_after_move() &&
718-
B.getEllipsisLoc().isValid())
717+
MRDOCS_ASSERT(!BaseType.valueless_after_move());
718+
if (B.getEllipsisLoc().isValid())
719719
{
720720
BaseType->IsPackExpansion = true;
721721
}
@@ -1341,11 +1341,7 @@ populate(
13411341
for (auto it = Template.Args.begin(); it != Template.Args.end();)
13421342
{
13431343
auto& arg = *it;
1344-
if (arg.valueless_after_move())
1345-
{
1346-
++it;
1347-
continue;
1348-
}
1344+
MRDOCS_ASSERT(!arg.valueless_after_move());
13491345
if (auto* T = dynamic_cast<TypeTArg*>(arg.operator->()))
13501346
{
13511347
MRDOCS_ASSERT(!T->Type.valueless_after_move());
@@ -1496,14 +1492,15 @@ populate(
14961492
Polymorphic<TParam>& I,
14971493
NamedDecl const* N)
14981494
{
1495+
MRDOCS_ASSERT(!I.valueless_after_move());
14991496
visit(N, [&]<typename DeclTy>(DeclTy const* P)
15001497
{
15011498
constexpr Decl::Kind kind =
15021499
DeclToKind<DeclTy>();
15031500

15041501
if constexpr(kind == Decl::TemplateTypeParm)
15051502
{
1506-
if (I.valueless_after_move())
1503+
if (I->Kind != TParamKind::Type)
15071504
{
15081505
I = Polymorphic<TParam>(std::in_place_type<TypeTParam>);
15091506
}
@@ -1532,7 +1529,7 @@ populate(
15321529
}
15331530
else if constexpr(kind == Decl::NonTypeTemplateParm)
15341531
{
1535-
if (I.valueless_after_move())
1532+
if (I->Kind != TParamKind::Constant)
15361533
{
15371534
I = Polymorphic<TParam>(std::in_place_type<ConstantTParam>);
15381535
}
@@ -1547,7 +1544,7 @@ populate(
15471544
}
15481545
else if constexpr(kind == Decl::TemplateTemplateParm)
15491546
{
1550-
if (I.valueless_after_move())
1547+
if (I->Kind != TParamKind::Template)
15511548
{
15521549
I = Polymorphic<TParam>(std::in_place_type<TemplateTParam>);
15531550
}
@@ -1563,8 +1560,7 @@ populate(
15631560
auto& Param
15641561
= i < Result->Params.size() ?
15651562
Result->Params[i] :
1566-
Result->Params.emplace_back(
1567-
nullable_traits<Polymorphic<TParam>>::null());
1563+
Result->Params.emplace_back(std::in_place_type<TypeTParam>);
15681564
populate(Param, TP);
15691565
}
15701566
if (TTPD->hasDefaultArgument() && !Result->Default)
@@ -1578,6 +1574,7 @@ populate(
15781574
MRDOCS_UNREACHABLE();
15791575
});
15801576

1577+
MRDOCS_ASSERT(!I.valueless_after_move());
15811578
if (I->Name.empty())
15821579
{
15831580
I->Name = extractName(N);
@@ -1615,10 +1612,10 @@ populate(
16151612
while (explicitIt != ExplicitTemplateParameters.end())
16161613
{
16171614
NamedDecl const* P = TPL->getParam(i);
1618-
auto& Param = i < TI.Params.size() ?
1619-
TI.Params[i] :
1620-
TI.Params.emplace_back(
1621-
nullable_traits<Polymorphic<TParam>>::null());
1615+
Polymorphic<TParam>& Param =
1616+
i < TI.Params.size() ?
1617+
TI.Params[i] :
1618+
TI.Params.emplace_back(std::in_place_type<TypeTParam>);
16221619
populate(Param, P);
16231620
++explicitIt;
16241621
++i;

0 commit comments

Comments
 (0)