Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,23 @@ populate(TypedefSymbol& I, clang::TypeAliasTemplateDecl const* D)
}
}

// A variable with no written initializer can still carry an implicit
// initializer in the AST. Any default-constructed class instance (`T t;`) gets
// an implicit construction expression located at the variable name, so the
// extracted source text is the variable name and would cause a spurious `= t`
// to be rendered in the docs. So, we intercept this case. A written `{}`, a
// copy-initialization such as `= x`, and literal initializers are left alone.
static
bool
isImplicitDefaultInit(clang::Expr const* E)
{
clang::CXXConstructExpr const* ctor =
dyn_cast<clang::CXXConstructExpr>(E->IgnoreImplicit());
return ctor != nullptr
&& ctor->getNumArgs() == 0
&& ctor->getParenOrBraceRange().isInvalid();
}

void
ASTVisitor::
populate(
Expand All @@ -1161,7 +1178,8 @@ populate(
I.IsConstinit |= D->hasAttr<clang::ConstInitAttr>();
I.IsConstexpr |= D->isConstexpr();
I.IsInline |= D->isInline();
if (clang::Expr const* E = D->getInit())
if (clang::Expr const* E = D->getInit();
E && !isImplicitDefaultInit(E))
{
populate(I.Initializer, E);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct tag_base {};

/** A default-constructed instance of a same-named tag type (see issue #1238). */
inline constexpr struct flag final : tag_base {} flag;

/** A copy-initialized variable. */
inline constexpr auto flag_copy = flag;

/** A value-initialized variable. */
inline constexpr tag_base braced{};

/** A variable with a literal initializer. */
inline constexpr int literal = 7;
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?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>
<source>
</source>
<kind>namespace</kind>
<id>//////////////////////////8=</id>
<extraction>regular</extraction>
<namespace-tranche>
<records>5sB+nY7A37FZIfir11OpIKC12Ok=</records>
<records>8tmm5w1vdZa8PYl9AaZ5HNozN/k=</records>
<variables>V/VOefC+Lirvlyv4ml0GPg3tkb8=</variables>
<variables>4BBlDC8MjV0Km82gDuPpLniry80=</variables>
<variables>w7084vhWPkLDZ/7kZBE9YeheM8E=</variables>
<variables>/2+SAVa0lxHgZkikhVVwJfO2tZY=</variables>
</namespace-tranche>
</namespace>
<record>
<name>flag</name>
<source>
<location>
<short-path>default-constructed-instance.cpp</short-path>
<source-path>default-constructed-instance.cpp</source-path>
<line-number>4</line-number>
<column-number>18</column-number>
<documented>1</documented>
</location>
</source>
<kind>record</kind>
<id>5sB+nY7A37FZIfir11OpIKC12Ok=</id>
<extraction>regular</extraction>
<parent>//////////////////////////8=</parent>
<doc-comment>
<brief>
<kind>brief</kind>
<text>
<kind>text</kind>
<literal>A default-constructed instance of a same-named tag type (see issue #1238).</literal>
</text>
</brief>
</doc-comment>
<key-kind>struct</key-kind>
<is-final>1</is-final>
<base>
<named>
<name>
<kind>identifier</kind>
<id>8tmm5w1vdZa8PYl9AaZ5HNozN/k=</id>
<identifier>tag_base</identifier>
</name>
</named>
</base>
<record-interface>
<record-tranche>
</record-tranche>
<record-tranche>
</record-tranche>
<record-tranche>
</record-tranche>
</record-interface>
</record>
<record>
<name>tag_base</name>
<source>
<location>
<short-path>default-constructed-instance.cpp</short-path>
<source-path>default-constructed-instance.cpp</source-path>
<line-number>1</line-number>
<column-number>1</column-number>
</location>
</source>
<kind>record</kind>
<id>8tmm5w1vdZa8PYl9AaZ5HNozN/k=</id>
<extraction>regular</extraction>
<parent>//////////////////////////8=</parent>
<key-kind>struct</key-kind>
<derived>5sB+nY7A37FZIfir11OpIKC12Ok=</derived>
<record-interface>
<record-tranche>
</record-tranche>
<record-tranche>
</record-tranche>
<record-tranche>
</record-tranche>
</record-interface>
</record>
<variable>
<name>braced</name>
<source>
<location>
<short-path>default-constructed-instance.cpp</short-path>
<source-path>default-constructed-instance.cpp</source-path>
<line-number>10</line-number>
<column-number>1</column-number>
<documented>1</documented>
</location>
</source>
<kind>variable</kind>
<id>V/VOefC+Lirvlyv4ml0GPg3tkb8=</id>
<extraction>regular</extraction>
<parent>//////////////////////////8=</parent>
<doc-comment>
<brief>
<kind>brief</kind>
<text>
<kind>text</kind>
<literal>A value-initialized variable.</literal>
</text>
</brief>
</doc-comment>
<named>
<name>
<kind>identifier</kind>
<id>8tmm5w1vdZa8PYl9AaZ5HNozN/k=</id>
<identifier>tag_base</identifier>
</name>
</named>
<initializer>{}</initializer>
<is-inline>1</is-inline>
<is-constexpr>1</is-constexpr>
</variable>
<variable>
<name>flag</name>
<source>
<location>
<short-path>default-constructed-instance.cpp</short-path>
<source-path>default-constructed-instance.cpp</source-path>
<line-number>4</line-number>
<column-number>1</column-number>
</location>
</source>
<kind>variable</kind>
<id>4BBlDC8MjV0Km82gDuPpLniry80=</id>
<extraction>regular</extraction>
<parent>//////////////////////////8=</parent>
<named>
<name>
<kind>identifier</kind>
<id>5sB+nY7A37FZIfir11OpIKC12Ok=</id>
<identifier>flag</identifier>
</name>
</named>
<is-inline>1</is-inline>
<is-constexpr>1</is-constexpr>
</variable>
<variable>
<name>flag_copy</name>
<source>
<location>
<short-path>default-constructed-instance.cpp</short-path>
<source-path>default-constructed-instance.cpp</source-path>
<line-number>7</line-number>
<column-number>1</column-number>
<documented>1</documented>
</location>
</source>
<kind>variable</kind>
<id>w7084vhWPkLDZ/7kZBE9YeheM8E=</id>
<extraction>regular</extraction>
<parent>//////////////////////////8=</parent>
<doc-comment>
<brief>
<kind>brief</kind>
<text>
<kind>text</kind>
<literal>A copy-initialized variable.</literal>
</text>
</brief>
</doc-comment>
<auto>
</auto>
<initializer>flag</initializer>
<is-inline>1</is-inline>
<is-constexpr>1</is-constexpr>
</variable>
<variable>
<name>literal</name>
<source>
<location>
<short-path>default-constructed-instance.cpp</short-path>
<source-path>default-constructed-instance.cpp</source-path>
<line-number>13</line-number>
<column-number>1</column-number>
<documented>1</documented>
</location>
</source>
<kind>variable</kind>
<id>/2+SAVa0lxHgZkikhVVwJfO2tZY=</id>
<extraction>regular</extraction>
<parent>//////////////////////////8=</parent>
<doc-comment>
<brief>
<kind>brief</kind>
<text>
<kind>text</kind>
<literal>A variable with a literal initializer.</literal>
</text>
</brief>
</doc-comment>
<named>
<name>
<kind>identifier</kind>
<identifier>int</identifier>
</name>
</named>
<initializer>7</initializer>
<is-inline>1</is-inline>
<is-constexpr>1</is-constexpr>
</variable>
</mrdocs>
Loading