@@ -17146,14 +17146,21 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
1714617146 FoldKind).isInvalid())
1714717147 Failed = true;
1714817148
17149+ // If the static_assert passes, only verify that
17150+ // the message is grammatically valid without evaluating it.
17151+ if (!Failed && AssertMessage && Cond.getBoolValue()) {
17152+ std::string Str;
17153+ EvaluateStaticAssertMessageAsString(AssertMessage, Str, Context,
17154+ /*ErrorOnInvalidMessage=*/false);
17155+ }
17156+
1714917157 // CWG2518
1715017158 // [dcl.pre]/p10 If [...] the expression is evaluated in the context of a
1715117159 // template definition, the declaration has no effect.
1715217160 bool InTemplateDefinition =
1715317161 getLangOpts().CPlusPlus && CurContext->isDependentContext();
1715417162
1715517163 if (!Failed && !Cond && !InTemplateDefinition) {
17156-
1715717164 SmallString<256> MsgBuffer;
1715817165 llvm::raw_svector_ostream Msg(MsgBuffer);
1715917166 bool HasMessage = AssertMessage;
@@ -17185,8 +17192,8 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
1718517192 << InnerCond->getSourceRange();
1718617193 DiagnoseStaticAssertDetails(InnerCond);
1718717194 } else {
17188- Diag(StaticAssertLoc , diag::err_static_assert_failed)
17189- << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
17195+ Diag(AssertExpr->getBeginLoc() , diag::err_static_assert_failed)
17196+ << !HasMessage << Msg.str() << AssertExpr->getSourceRange();
1719017197 PrintContextStack();
1719117198 }
1719217199 Failed = true;
0 commit comments