From 037619964f1cf3345deaf4460f381194feb421be Mon Sep 17 00:00:00 2001 From: topisani Date: Fri, 22 Dec 2017 04:09:48 +0100 Subject: [PATCH] Comments and (failing) tests --- src/libclang/namespace_parser.cpp | 7 +++++-- test/cpp_namespace.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/libclang/namespace_parser.cpp b/src/libclang/namespace_parser.cpp index e7df48f..7938ad4 100644 --- a/src/libclang/namespace_parser.cpp +++ b/src/libclang/namespace_parser.cpp @@ -24,7 +24,9 @@ namespace if (skip_if(stream, "inline")) is_inline = true; - // C++17 nested namespace declarations + // C++17 nested namespace declarations get one cursor per nested name. + // The first cursor starts with the `namespace` keyword, and the + // following start with the `::` separator. Either way, it is skipped. if (!detail::skip_if(stream, "namespace")) skip(stream, "::"); @@ -40,7 +42,8 @@ namespace auto other_attributes = parse_attributes(stream); attributes.insert(attributes.end(), other_attributes.begin(), other_attributes.end()); - // C++17 nested namespace declarations + // If the next token is not `::`, there are no more nested namespace + // names, and we expect to see an opening brace. if (!detail::skip_if(stream, "::")) skip(stream, "{"); diff --git a/test/cpp_namespace.cpp b/test/cpp_namespace.cpp index 4b08ba7..20f9833 100644 --- a/test/cpp_namespace.cpp +++ b/test/cpp_namespace.cpp @@ -33,6 +33,16 @@ namespace c /// namespace { /// } namespace {} + +/// namespace e{ +/// namespace f{ +/// } +/// } +namespace e::f {} + +/// \entity e::f +/// namespace f{ +/// } )"; auto file = parse({}, "cpp_namespace.cpp", code); @@ -69,6 +79,19 @@ namespace {} REQUIRE(!ns.is_inline()); REQUIRE(no_children == 0u); } + else if (ns.name() == "e") + { + REQUIRE(!ns.is_anonymous()); + REQUIRE(!ns.is_inline()); + REQUIRE(no_children == 1u); + } + else if (ns.name() == "f") + { + REQUIRE(!ns.is_anonymous()); + check_parent(ns, "e", "e::f"); + REQUIRE(!ns.is_inline()); + REQUIRE(no_children == 0u); + } else REQUIRE(false); });