From f389b96800278f3540762d88b7a94ca506758e64 Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Tue, 9 Jul 2024 18:42:38 +0200 Subject: [PATCH] Fixed #654: `noexcept` expression in primary template. --- InsightsHelpers.cpp | 25 ++++++++++++++++++------- tests/Issue654.cpp | 4 ++++ tests/Issue654.expect | 4 ++++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 tests/Issue654.cpp create mode 100644 tests/Issue654.expect diff --git a/InsightsHelpers.cpp b/InsightsHelpers.cpp index 385f523..54b697d 100644 --- a/InsightsHelpers.cpp +++ b/InsightsHelpers.cpp @@ -1495,14 +1495,15 @@ std::string GetName(const VarDecl& VD) } //----------------------------------------------------------------------------- -static bool EvaluateAsBoolenCondition(const Expr& expr, const Decl& decl) +static std::optional 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; } //----------------------------------------------------------------------------- @@ -1510,13 +1511,23 @@ const std::string GetNoExcept(const FunctionDecl& decl) { const auto* func = decl.getType()->castAs(); - 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; diff --git a/tests/Issue654.cpp b/tests/Issue654.cpp new file mode 100644 index 0000000..e897285 --- /dev/null +++ b/tests/Issue654.cpp @@ -0,0 +1,4 @@ +template +void f() noexcept(B) +{ +} diff --git a/tests/Issue654.expect b/tests/Issue654.expect new file mode 100644 index 0000000..e897285 --- /dev/null +++ b/tests/Issue654.expect @@ -0,0 +1,4 @@ +template +void f() noexcept(B) +{ +}