llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Carlos Galvez (carlosgalvezp) <details> <summary>Changes</summary> Fixes #<!-- -->154493 --- Full diff: https://github.com/llvm/llvm-project/pull/154545.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+3) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+5) - (modified) clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp (+12-1) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 5c780851ca589..5a837642ca99b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -188,6 +188,9 @@ Improvements to Clang's diagnostics potential misaligned members get processed before they can get discarded. (#GH144729) +- Fixed false positive in ``-Wmissing-noreturn`` diagnostic when it was requiring the usage of + ``[[noreturn]]`` on lambdas before C++23 (#GH154493). + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 7a185106e4c6e..8c3130a7d4735 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1989,6 +1989,11 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) { isKnownToAlwaysThrow(FD)) { NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context)); + // [[noreturn]] can only be added to lambdas since C++23 + if (const auto *MD = dyn_cast<CXXMethodDecl>(FD); + MD && !S.getLangOpts().CPlusPlus23 && isLambdaCallOperator(MD)) + return; + // Emit a diagnostic suggesting the function being marked [[noreturn]]. S.Diag(FD->getLocation(), diag::warn_suggest_noreturn_function) << /*isFunction=*/0 << FD; diff --git a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp index 8beffcd39e85c..ef70250f1f468 100644 --- a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp +++ b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Wmissing-noreturn -verify %s +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Wmissing-noreturn -verify -std=c++17 %s +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -Wmissing-noreturn -verify -std=c++23 %s namespace std { class string { @@ -16,6 +17,16 @@ void throwError(const std::string& msg) { // expected-warning {{function 'throwE throw std::runtime_error(msg); } +// We cannot use the [[noreturn]] attribute on lambdas until C++23 +void lambda(const std::string& msg) { +#if __cplusplus >= 202302L + auto l1 = [&msg](){ throw std::runtime_error(msg); }; // expected-warning {{function 'operator()' could be declared with attribute 'noreturn'}} + auto l2 = [&msg] [[noreturn]] (){ throw std::runtime_error(msg); }; +#else + auto l1 = [&msg](){ throw std::runtime_error(msg); }; +#endif +} + // The non-void caller should not warn about missing return. int ensureZero(int i) { if (i == 0) return 0; `````````` </details> https://github.com/llvm/llvm-project/pull/154545 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits