Fix handling of template template arguments which are not expressions (#199)

This commit is contained in:
Bartek Kryza
2023-10-24 18:29:04 +02:00
parent 57bc2f7309
commit 79801b2936
4 changed files with 21 additions and 5 deletions

View File

@@ -238,6 +238,11 @@ std::string to_string(const clang::Expr *expr)
return result;
}
std::string to_string(const clang::ValueDecl *val)
{
return val->getQualifiedNameAsString();
}
std::string to_string(const clang::Stmt *stmt)
{
const clang::LangOptions lang_options;

View File

@@ -111,6 +111,8 @@ std::string to_string(
std::string to_string(const clang::Expr *expr);
std::string to_string(const clang::ValueDecl *val);
std::string to_string(const clang::Stmt *stmt);
std::string to_string(const clang::FunctionTemplateDecl *decl);

View File

@@ -76,7 +76,7 @@ clang::ASTContext *call_expression_context::get_ast_context() const
}
if (current_method_decl_ != nullptr) {
return &current_function_decl_->getASTContext();
return &current_method_decl_->getASTContext();
}
return nullptr;

View File

@@ -1601,11 +1601,20 @@ bool translation_unit_visitor::process_template_parameters(
clang::dyn_cast_or_null<clang::TemplateTemplateParmDecl>(
parameter);
std::optional<std::string> default_arg;
if (template_template_parameter->hasDefaultArgument())
default_arg = common::to_string(
if (template_template_parameter->hasDefaultArgument()) {
const auto &def_arg =
template_template_parameter->getDefaultArgument()
.getArgument()
.getAsExpr());
.getArgument();
if (def_arg.getKind() ==
clang::TemplateArgument::ArgKind::Expression) {
default_arg = common::to_string(def_arg.getAsExpr());
}
else if (def_arg.getKind() ==
clang::TemplateArgument::ArgKind::Declaration) {
default_arg = common::to_string(def_arg.getAsDecl());
}
}
auto ct = template_parameter::make_template_template_type(
template_template_parameter->getNameAsString(), default_arg,
template_template_parameter->isParameterPack());