Skip to content

Commit

Permalink
Fixed #654: noexcept expression in primary template.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasfertig committed Jul 9, 2024
1 parent e473634 commit f389b96
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
25 changes: 18 additions & 7 deletions InsightsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,28 +1495,39 @@ std::string GetName(const VarDecl& VD)
}
//-----------------------------------------------------------------------------

static bool EvaluateAsBoolenCondition(const Expr& expr, const Decl& decl)
static std::optional<bool> EvaluateAsBoolenCondition(const Expr& expr, const Decl& decl)
{
bool r{false};

const bool res = expr.EvaluateAsBooleanCondition(r, decl.getASTContext());
assert(res);
if(expr.EvaluateAsBooleanCondition(r, decl.getASTContext())) {
return {r};
}

return r;
return std::nullopt;
}
//-----------------------------------------------------------------------------

const std::string GetNoExcept(const FunctionDecl& decl)
{
const auto* func = decl.getType()->castAs<FunctionProtoType>();

if(func and func->hasNoexceptExceptionSpec()) {
if(func and func->hasNoexceptExceptionSpec() and not isUnresolvedExceptionSpec(func->getExceptionSpecType())) {
std::string ret{kwSpaceNoexcept};

if(const auto* expr = func->getNoexceptExpr()) {
const auto value = EvaluateAsBoolenCondition(*expr, decl);
ret += "("sv;

if(const auto value = EvaluateAsBoolenCondition(*expr, decl); value) {
ret += details::ConvertToBoolString(*value);
} else {
OutputFormatHelper ofm{};
CodeGenerator cg{ofm};
cg.InsertArg(expr);

ret += ofm.GetString();
}

ret += StrCat("("sv, details::ConvertToBoolString(value), ")"sv);
ret += ")"sv;
}

return ret;
Expand Down
4 changes: 4 additions & 0 deletions tests/Issue654.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template<bool B>
void f() noexcept(B)
{
}
4 changes: 4 additions & 0 deletions tests/Issue654.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template<bool B>
void f() noexcept(B)
{
}

0 comments on commit f389b96

Please sign in to comment.