@@ -2902,28 +2902,37 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) {
29022902 }
29032903
29042904 StringRef Str;
2905- if (AL.isStandardAttributeSyntax () && !AL.getScopeName ()) {
2906- // The standard attribute cannot be applied to variable declarations such
2907- // as a function pointer.
2908- if (isa<VarDecl>(D))
2909- S.Diag (AL.getLoc (), diag::warn_attribute_wrong_decl_type)
2910- << AL << AL.isRegularKeywordAttribute ()
2911- << ExpectedFunctionOrClassOrEnum;
2912-
2913- // If this is spelled as the standard C++17 attribute, but not in C++17,
2914- // warn about using it as an extension. If there are attribute arguments,
2915- // then claim it's a C++20 extension instead. C23 supports this attribute
2916- // with the message; no extension warning is needed there beyond the one
2917- // already issued for accepting attributes in older modes.
2918- const LangOptions &LO = S.getLangOpts ();
2919- if (AL.getNumArgs () == 1 ) {
2920- if (LO.CPlusPlus && !LO.CPlusPlus20 )
2921- S.Diag (AL.getLoc (), diag::ext_cxx20_attr) << AL;
2922-
2923- if (!S.checkStringLiteralArgumentAttr (AL, 0 , Str, nullptr ))
2905+ if (AL.isStandardAttributeSyntax ()) {
2906+ // If this is spelled [[clang::warn_unused_result]] we look for an optional
2907+ // string literal. This is not gated behind any specific version of the
2908+ // standard.
2909+ if (AL.isClangScope ()) {
2910+ if (AL.getNumArgs () == 1 &&
2911+ !S.checkStringLiteralArgumentAttr (AL, 0 , Str, nullptr ))
29242912 return ;
2925- } else if (LO.CPlusPlus && !LO.CPlusPlus17 )
2926- S.Diag (AL.getLoc (), diag::ext_cxx17_attr) << AL;
2913+ } else if (!AL.getScopeName ()) {
2914+ // The standard attribute cannot be applied to variable declarations such
2915+ // as a function pointer.
2916+ if (isa<VarDecl>(D))
2917+ S.Diag (AL.getLoc (), diag::warn_attribute_wrong_decl_type)
2918+ << AL << AL.isRegularKeywordAttribute ()
2919+ << ExpectedFunctionOrClassOrEnum;
2920+
2921+ // If this is spelled as the standard C++17 attribute, but not in C++17,
2922+ // warn about using it as an extension. If there are attribute arguments,
2923+ // then claim it's a C++20 extension instead. C23 supports this attribute
2924+ // with the message; no extension warning is needed there beyond the one
2925+ // already issued for accepting attributes in older modes.
2926+ const LangOptions &LO = S.getLangOpts ();
2927+ if (AL.getNumArgs () == 1 ) {
2928+ if (LO.CPlusPlus && !LO.CPlusPlus20 )
2929+ S.Diag (AL.getLoc (), diag::ext_cxx20_attr) << AL;
2930+
2931+ if (!S.checkStringLiteralArgumentAttr (AL, 0 , Str, nullptr ))
2932+ return ;
2933+ } else if (LO.CPlusPlus && !LO.CPlusPlus17 )
2934+ S.Diag (AL.getLoc (), diag::ext_cxx17_attr) << AL;
2935+ }
29272936 }
29282937
29292938 if ((!AL.isGNUAttribute () &&
0 commit comments