Skip to content

Commit

Permalink
feat: deducing this
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni authored Feb 9, 2024
1 parent 91d6742 commit 67fa963
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/mrdocs/Metadata/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ union FnFlags1
BitFlag<0> isNodiscard;

BitField<1, 3, ExplicitKind> explicitSpec;

BitFlag<4> isExplicitObjectMemberFunction;
};

// KRYSTIAN TODO: attributes (nodiscard, deprecated, and carries_dependency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{#if (eq symbol.class "normal")}}{{>declarator-before symbol.return}}
{{/if~}}
{{>declarator-id symbol link=symbol.template.primary}}
({{#each symbol.params}}{{#unless (and @first @last)}}
({{#if symbol.isExplicitObjectMemberFunction}}this {{/if}}{{#each symbol.params}}{{#unless (and @first @last)}}
{{/unless}}{{>declarator type decl-name=name~}}
{{#if default}} = {{default}}{{/if~}}
{{#unless @last}},{{/unless~}}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ class ASTVisitor
D->getStorageClass());

I.specs1.isNodiscard |= D->template hasAttr<WarnUnusedResultAttr>();

I.specs1.isExplicitObjectMemberFunction |= D->hasCXXExplicitFunctionObjectParameter();
//
// CXXMethodDecl
//
Expand Down
1 change: 1 addition & 0 deletions src/lib/Gen/xml/CXXTags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ inline void write(FnFlags1 const& bits, XMLTags& tags)

fw.write(&FnFlags1::explicitSpec, "explicit-spec");
fw.write(&FnFlags1::isNodiscard, "nodiscard");
fw.write(&FnFlags1::isExplicitObjectMemberFunction, "is-explicit-object-member-function");
}


Expand Down
2 changes: 1 addition & 1 deletion src/lib/Lib/SingleFileDB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SingleFileDB
std::vector<std::string> cmds;
cmds.emplace_back("clang");
cmds.emplace_back("-fsyntax-only");
cmds.emplace_back("-std=c++20");
cmds.emplace_back("-std=c++23");
cmds.emplace_back("-pedantic-errors");
cmds.emplace_back("-Werror");
cmds.emplace_back(fileName);
Expand Down
1 change: 1 addition & 0 deletions src/lib/Metadata/DomMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ DomInfo<T>::construct() const
set_flag("isVolatile", I_.specs0.isVolatile.get());
set_flag("isFinal", I_.specs0.isFinal.get());
set_flag("isNodiscard", I_.specs1.isNodiscard.get());
set_flag("isExplicitObjectMemberFunction", I_.specs1.isExplicitObjectMemberFunction.get());

auto const set_string =
[&](dom::String key, dom::String value)
Expand Down
8 changes: 8 additions & 0 deletions test-files/old-tests/explicit-object-parameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct Optional
{
template <typename Self>
constexpr auto&& value(this Self&& self);

template <typename Self>
constexpr auto&& value(this Self&& self, int x);
};
48 changes: 48 additions & 0 deletions test-files/old-tests/explicit-object-parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
<namespace id="//////////////////////////8=">
<struct name="Optional" id="/TAtWMuvF+kz/B0ChmDlGQtnkaA=">
<file path="explicit-object-parameter.cpp" line="1" class="def"/>
<template>
<tparam name="Self" class="type"/>
<function name="value" id="XLLL4h9bZlRyA4AQMlfVPCuwMoU=">
<file path="explicit-object-parameter.cpp" line="4"/>
<attr id="constexpr-kind" name="constexpr" value="1"/>
<attr id="is-explicit-object-member-function"/>
<return>
<type class="rvalue-reference">
<pointee-type name="auto"/>
</type>
</return>
<param name="self">
<type class="rvalue-reference">
<pointee-type name="Self"/>
</type>
</param>
</function>
</template>
<template>
<tparam name="Self" class="type"/>
<function name="value" id="aOpxAmSvyM7g6X3lLAJG5i3CTZA=">
<file path="explicit-object-parameter.cpp" line="7"/>
<attr id="constexpr-kind" name="constexpr" value="1"/>
<attr id="is-explicit-object-member-function"/>
<return>
<type class="rvalue-reference">
<pointee-type name="auto"/>
</type>
</return>
<param name="self">
<type class="rvalue-reference">
<pointee-type name="Self"/>
</type>
</param>
<param name="x">
<type name="int"/>
</param>
</function>
</template>
</struct>
</namespace>
</mrdocs>

0 comments on commit 67fa963

Please sign in to comment.