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:
Julian Rüth 2021-02-03 19:28:49 +01:00 committed by GitHub
commit 36b64d29b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -15,7 +15,11 @@ cpp_entity_kind cpp_language_linkage::kind() 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
}

View file

@ -36,6 +36,10 @@ extern "C++" // yup
enum e {};
}
/// extern "C++"{
/// }
extern "C++" {}
enum f {};
)";
@ -50,7 +54,7 @@ enum f {};
else
REQUIRE(false);
});
REQUIRE(count == 2u);
REQUIRE(count == 3u);
// check enums for their correct parent
count = test_visit<cpp_enum>(*file,