This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG66202d83b5d4: Make 'static assertion failed' diagnostics point to the static assertion… (authored by sousajo, committed by aaron.ballman). Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D147745/new/ https://reviews.llvm.org/D147745 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaCXX/static-assert.cpp 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, + "" + ); } Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -16820,19 +16820,20 @@ if (InnerCond && isa<ConceptSpecializationExpr>(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<CXXBoolLiteralExpr>(InnerCond) && !isa<IntegerLiteral>(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/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 <https://github.com/llvm/llvm-project/issues/57906>`_) +- Clang's "static assertion failed" diagnostic now points to the static assertion + expression instead of pointing to the ``static_assert`` token. + (`#61951 <https://github.com/llvm/llvm-project/issues/61951>`_) Bug Fixes in This Version -------------------------
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, + "" + ); } Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -16820,19 +16820,20 @@ if (InnerCond && isa<ConceptSpecializationExpr>(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<CXXBoolLiteralExpr>(InnerCond) && !isa<IntegerLiteral>(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/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 <https://github.com/llvm/llvm-project/issues/57906>`_) +- Clang's "static assertion failed" diagnostic now points to the static assertion + expression instead of pointing to the ``static_assert`` token. + (`#61951 <https://github.com/llvm/llvm-project/issues/61951>`_) Bug Fixes in This Version -------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits