Segfault when parsing an empty extern "C" {} block (#110)
extern declaration blocks can be empty: https://en.cppreference.com/w/cpp/language/language_linkage
This commit is contained in:
parent
9ab6ef877a
commit
36b64d29b9
2 changed files with 10 additions and 2 deletions
|
|
@ -15,7 +15,11 @@ cpp_entity_kind cpp_language_linkage::kind() noexcept
|
||||||
|
|
||||||
bool cpp_language_linkage::is_block() const noexcept
|
bool cpp_language_linkage::is_block() const noexcept
|
||||||
{
|
{
|
||||||
DEBUG_ASSERT(begin() != end(), detail::assert_handler{}, "empty container");
|
if (begin() == end())
|
||||||
|
{
|
||||||
|
// An empty container must be a "block" of the form: extern "C" {}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return std::next(begin()) != end(); // more than one entity, so block
|
return std::next(begin()) != end(); // more than one entity, so block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ extern "C++" // yup
|
||||||
enum e {};
|
enum e {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// extern "C++"{
|
||||||
|
/// }
|
||||||
|
extern "C++" {}
|
||||||
|
|
||||||
enum f {};
|
enum f {};
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|
@ -50,7 +54,7 @@ enum f {};
|
||||||
else
|
else
|
||||||
REQUIRE(false);
|
REQUIRE(false);
|
||||||
});
|
});
|
||||||
REQUIRE(count == 2u);
|
REQUIRE(count == 3u);
|
||||||
|
|
||||||
// check enums for their correct parent
|
// check enums for their correct parent
|
||||||
count = test_visit<cpp_enum>(*file,
|
count = test_visit<cpp_enum>(*file,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue