Fix issue when parsing anonymous namespaces
This commit is contained in:
parent
6a09a5253e
commit
75fbc577ad
3 changed files with 25 additions and 2 deletions
|
|
@ -60,6 +60,12 @@ namespace cppast
|
|||
return inline_;
|
||||
}
|
||||
|
||||
/// \returns Whether or not the namespace is anonymous.
|
||||
bool is_anonymous() const noexcept
|
||||
{
|
||||
return name().empty();
|
||||
}
|
||||
|
||||
private:
|
||||
cpp_namespace(std::string name, bool is_inline)
|
||||
: cpp_entity(std::move(name)), inline_(is_inline)
|
||||
|
|
|
|||
|
|
@ -27,9 +27,12 @@ namespace
|
|||
skip_attribute(stream);
|
||||
|
||||
// <identifier> {
|
||||
// or when anonymous: {
|
||||
if (detail::skip_if(stream, "{"))
|
||||
return cpp_namespace::builder("", is_inline);
|
||||
|
||||
auto& name = stream.get().value();
|
||||
skip(stream, "{");
|
||||
|
||||
return cpp_namespace::builder(name.c_str(), is_inline);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ namespace c
|
|||
/// }
|
||||
namespace d {}
|
||||
}
|
||||
|
||||
/// namespace {
|
||||
/// }
|
||||
namespace {}
|
||||
)";
|
||||
|
||||
auto file = parse({}, "cpp_namespace.cpp", code);
|
||||
|
|
@ -36,29 +40,39 @@ namespace c
|
|||
auto no_children = count_children(ns);
|
||||
if (ns.name() == "a")
|
||||
{
|
||||
REQUIRE(!ns.is_anonymous());
|
||||
REQUIRE(!ns.is_inline());
|
||||
REQUIRE(no_children == 0u);
|
||||
}
|
||||
else if (ns.name() == "b")
|
||||
{
|
||||
REQUIRE(!ns.is_anonymous());
|
||||
REQUIRE(ns.is_inline());
|
||||
REQUIRE(no_children == 0u);
|
||||
}
|
||||
else if (ns.name() == "c")
|
||||
{
|
||||
REQUIRE(!ns.is_anonymous());
|
||||
REQUIRE(!ns.is_inline());
|
||||
REQUIRE(no_children == 1u);
|
||||
}
|
||||
else if (ns.name() == "d")
|
||||
{
|
||||
REQUIRE(!ns.is_anonymous());
|
||||
check_parent(ns, "c", "c::d");
|
||||
REQUIRE(!ns.is_inline());
|
||||
REQUIRE(no_children == 0u);
|
||||
}
|
||||
else if (ns.name() == "")
|
||||
{
|
||||
REQUIRE(ns.is_anonymous());
|
||||
REQUIRE(!ns.is_inline());
|
||||
REQUIRE(no_children == 0u);
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
});
|
||||
REQUIRE(count == 4u);
|
||||
REQUIRE(count == 5u);
|
||||
}
|
||||
|
||||
TEST_CASE("cpp_namespace_alias")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue