Workaround converison operator parsing bug
This commit is contained in:
parent
204961b7b1
commit
4534bd2842
2 changed files with 68 additions and 28 deletions
|
|
@ -393,9 +393,11 @@ namespace
|
||||||
{
|
{
|
||||||
// look if the type has a declaration that is a template
|
// look if the type has a declaration that is a template
|
||||||
auto decl = clang_getTypeDeclaration(type);
|
auto decl = clang_getTypeDeclaration(type);
|
||||||
if (is_direct_templated(decl))
|
auto count = clang_Type_getNumTemplateArguments(clang_getCursorType(decl));
|
||||||
|
if (count > 0 || is_direct_templated(decl))
|
||||||
return decl;
|
return decl;
|
||||||
|
else
|
||||||
|
{
|
||||||
// look if the templ_name matches a template template parameter
|
// look if the templ_name matches a template template parameter
|
||||||
auto param = clang_getNullCursor();
|
auto param = clang_getNullCursor();
|
||||||
detail::visit_children(cur, [&](const CXCursor& child) {
|
detail::visit_children(cur, [&](const CXCursor& child) {
|
||||||
|
|
@ -409,15 +411,19 @@ namespace
|
||||||
});
|
});
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<cpp_type> try_parse_instantiation_type(const detail::parse_context&,
|
std::unique_ptr<cpp_type> try_parse_instantiation_type(const detail::parse_context&,
|
||||||
const CXCursor& cur, const CXType& type)
|
const CXCursor& cur, const CXType& type)
|
||||||
{
|
{
|
||||||
return make_leave_type(type, [&](std::string&& spelling) -> std::unique_ptr<cpp_type> {
|
return make_leave_type(type, [&](std::string&& spelling) -> std::unique_ptr<cpp_type> {
|
||||||
auto ptr = spelling.c_str();
|
auto ptr = spelling.c_str();
|
||||||
|
|
||||||
std::string templ_name;
|
std::string templ_name;
|
||||||
for (; *ptr && *ptr != '<'; ++ptr)
|
for (; *ptr && *ptr != '<'; ++ptr)
|
||||||
templ_name += *ptr;
|
templ_name += *ptr;
|
||||||
|
if (*ptr != '<')
|
||||||
|
return nullptr;
|
||||||
++ptr;
|
++ptr;
|
||||||
|
|
||||||
auto templ = get_instantiation_template(cur, type, templ_name);
|
auto templ = get_instantiation_template(cur, type, templ_name);
|
||||||
|
|
@ -429,7 +435,8 @@ namespace
|
||||||
|
|
||||||
// parse arguments
|
// parse arguments
|
||||||
// i.e. not parse really, just add the string
|
// i.e. not parse really, just add the string
|
||||||
DEBUG_ASSERT(!spelling.empty() && spelling.back() == '>', detail::assert_handler{});
|
if (spelling.empty() || spelling.back() != '>')
|
||||||
|
return nullptr;
|
||||||
spelling.pop_back();
|
spelling.pop_back();
|
||||||
builder.add_unexposed_arguments(ptr);
|
builder.add_unexposed_arguments(ptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,18 +157,36 @@ TEST_CASE("cpp_conversion_op")
|
||||||
namespace ns
|
namespace ns
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using type = char;
|
struct type {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// most of it only need to be check in member function
|
// most of it only need to be check in member function
|
||||||
struct foo
|
struct foo
|
||||||
{
|
{
|
||||||
/// operator int&();
|
/// operator int&();
|
||||||
operator int&();
|
operator int&()
|
||||||
|
{
|
||||||
|
static int i;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
/// explicit operator bool()const;
|
/// explicit operator bool()const;
|
||||||
explicit operator bool() const;
|
explicit operator bool() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// constexpr operator ns::type<int>();
|
/// constexpr operator ns::type<int>();
|
||||||
constexpr operator ns::type<int>();
|
constexpr operator ns::type<int>()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// constexpr operator ns::type<char>();
|
||||||
|
constexpr operator ns::type<char>()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|
@ -177,7 +195,7 @@ struct foo
|
||||||
auto count = test_visit<cpp_conversion_op>(*file, [&](const cpp_conversion_op& op) {
|
auto count = test_visit<cpp_conversion_op>(*file, [&](const cpp_conversion_op& op) {
|
||||||
REQUIRE(count_children(op.parameters()) == 0u);
|
REQUIRE(count_children(op.parameters()) == 0u);
|
||||||
REQUIRE(!op.is_variadic());
|
REQUIRE(!op.is_variadic());
|
||||||
REQUIRE(op.body_kind() == cpp_function_declaration);
|
REQUIRE(op.body_kind() == cpp_function_definition);
|
||||||
REQUIRE(op.ref_qualifier() == cpp_ref_none);
|
REQUIRE(op.ref_qualifier() == cpp_ref_none);
|
||||||
REQUIRE(!op.virtual_info());
|
REQUIRE(!op.virtual_info());
|
||||||
REQUIRE(!op.noexcept_condition());
|
REQUIRE(!op.noexcept_condition());
|
||||||
|
|
@ -198,17 +216,32 @@ struct foo
|
||||||
}
|
}
|
||||||
else if (!op.is_explicit() && op.is_constexpr())
|
else if (!op.is_explicit() && op.is_constexpr())
|
||||||
{
|
{
|
||||||
REQUIRE(op.name() == "operator ns::type<int>");
|
|
||||||
cpp_template_instantiation_type::builder builder(
|
|
||||||
cpp_template_ref(cpp_entity_id(""), "ns::type"));
|
|
||||||
builder.add_unexposed_arguments("int");
|
|
||||||
REQUIRE(equal_types(idx, op.return_type(), *builder.finish()));
|
|
||||||
REQUIRE(op.cv_qualifier() == cpp_cv_none);
|
REQUIRE(op.cv_qualifier() == cpp_cv_none);
|
||||||
|
if (op.name() == "operator ns::type<int>")
|
||||||
|
{
|
||||||
|
REQUIRE(op.return_type().kind() == cpp_type_kind::template_instantiation_t);
|
||||||
|
auto& inst = static_cast<const cpp_template_instantiation_type&>(op.return_type());
|
||||||
|
|
||||||
|
REQUIRE(inst.primary_template().name() == "ns::type");
|
||||||
|
REQUIRE(!inst.arguments_exposed());
|
||||||
|
REQUIRE(inst.unexposed_arguments() == "int");
|
||||||
|
}
|
||||||
|
else if (op.name() == "operator ns::type<char>")
|
||||||
|
{
|
||||||
|
REQUIRE(op.return_type().kind() == cpp_type_kind::template_instantiation_t);
|
||||||
|
auto& inst = static_cast<const cpp_template_instantiation_type&>(op.return_type());
|
||||||
|
|
||||||
|
REQUIRE(inst.primary_template().name() == "ns::type");
|
||||||
|
REQUIRE(!inst.arguments_exposed());
|
||||||
|
REQUIRE(inst.unexposed_arguments() == "char");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
REQUIRE(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
REQUIRE(false);
|
REQUIRE(false);
|
||||||
});
|
});
|
||||||
REQUIRE(count == 3u);
|
REQUIRE(count == 4u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("cpp_constructor")
|
TEST_CASE("cpp_constructor")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue