Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -218,6 +218,9 @@ - Clang now avoids unnecessary diagnostic warnings for obvious expressions in the case of binary operators with logical OR operations. (`#57906 `_) +- Clang's "static assertion failed" diagnostic now points to the static assertion + expression instead of pointing to the ``static_assert`` token. + (`#61951 `_) Bug Fixes in This Version ------------------------- Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -16820,19 +16820,20 @@ if (InnerCond && isa(InnerCond)) { // Drill down into concept specialization expressions to see why they // weren't satisfied. - Diag(StaticAssertLoc, diag::err_static_assert_failed) - << !AssertMessage << Msg.str() << AssertExpr->getSourceRange(); + Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed) + << !AssertMessage << Msg.str() << AssertExpr->getSourceRange(); ConstraintSatisfaction Satisfaction; if (!CheckConstraintSatisfaction(InnerCond, Satisfaction)) DiagnoseUnsatisfiedConstraint(Satisfaction); } else if (InnerCond && !isa(InnerCond) && !isa(InnerCond)) { - Diag(StaticAssertLoc, diag::err_static_assert_requirement_failed) - << InnerCondDescription << !AssertMessage - << Msg.str() << InnerCond->getSourceRange(); + Diag(InnerCond->getBeginLoc(), + diag::err_static_assert_requirement_failed) + << InnerCondDescription << !AssertMessage << Msg.str() + << InnerCond->getSourceRange(); DiagnoseStaticAssertDetails(InnerCond); } else { - Diag(StaticAssertLoc, diag::err_static_assert_failed) + Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed) << !AssertMessage << Msg.str() << AssertExpr->getSourceRange(); PrintContextStack(); } Index: clang/test/SemaCXX/static-assert.cpp =================================================================== --- clang/test/SemaCXX/static-assert.cpp +++ clang/test/SemaCXX/static-assert.cpp @@ -287,5 +287,28 @@ static_assert(CHECK_4(a) && A_IS_B, ""); // expected-error {{failed}} \ // expected-note {{evaluates to '4 == 5'}} + static_assert( + false, // expected-error {{static assertion failed}} + "" + ); + + static_assert( + true && false, // expected-error {{static assertion failed due to requirement 'true && false'}} + "" + ); + + static_assert( + // with a comment here + true && false, // expected-error {{static assertion failed due to requirement 'true && false'}} + "" + ); + + static_assert( + // with a comment here + (true && // expected-error {{static assertion failed due to requirement '(true && false) || false'}} + false) + || false, + "" + ); }