https://github.com/halbi2 updated https://github.com/llvm/llvm-project/pull/137899
>From 238d73776c85ed22386ac494f275261638cd40d3 Mon Sep 17 00:00:00 2001 From: halbi2 <hehira...@gmail.com> Date: Mon, 28 Apr 2025 20:07:43 -0400 Subject: [PATCH] [clang] Warn about deprecated volatile-qualified return types The old codepath in GetFullTypeForDeclarator was under "if (not a class type)" so that it failed to warn for class types. Move the diagnostic outside of the "if" so that it warns in the proper situations. Fixes #133380 --- clang/docs/ReleaseNotes.rst | 3 +++ clang/lib/Sema/SemaType.cpp | 10 +++++----- clang/test/CXX/expr/expr.const/p2-0x.cpp | 2 +- clang/test/SemaCXX/deprecated.cpp | 7 +++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3105d8b481560..d71556c351e85 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -420,6 +420,9 @@ Improvements to Clang's diagnostics the ``-Wc99-designator`` diagnostic group, as they also are about the behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037 +- ``-Wvolatile`` now warns about volatile-qualified class return types + as well as volatile-qualified scalar return types. Fixes #GH133380 + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 6e7ee8b5506ff..31bdc97d014d6 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5056,13 +5056,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T; } else diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex); - - // C++2a [dcl.fct]p12: - // A volatile-qualified return type is deprecated - if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20) - S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T; } + // C++2a [dcl.fct]p12: + // A volatile-qualified return type is deprecated + if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20) + S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T; + // Objective-C ARC ownership qualifiers are ignored on the function // return type (by type canonicalization). Complain if this attribute // was written here. diff --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp b/clang/test/CXX/expr/expr.const/p2-0x.cpp index df5ce108aca82..c6c3381be5523 100644 --- a/clang/test/CXX/expr/expr.const/p2-0x.cpp +++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp @@ -356,7 +356,7 @@ namespace LValueToRValue { // - a non-volatile glvalue of literal type that refers to a non-volatile // temporary object whose lifetime has not ended, initialized with a // constant expression; - constexpr volatile S f() { return S(); } + constexpr volatile S f() { return S(); } // cxx20-warning {{volatile-qualified return type 'volatile S' is deprecated}} static_assert(f().i, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}} static_assert(((volatile const S&&)(S)0).i, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}} } diff --git a/clang/test/SemaCXX/deprecated.cpp b/clang/test/SemaCXX/deprecated.cpp index a24b40d8e622a..061fa8b54dff1 100644 --- a/clang/test/SemaCXX/deprecated.cpp +++ b/clang/test/SemaCXX/deprecated.cpp @@ -231,6 +231,13 @@ namespace DeprecatedVolatile { a = c = a; b += a; } + + volatile struct amber jurassic(); + // cxx20-warning@-1 {{volatile-qualified return type 'volatile struct amber' is deprecated}} + void trex(volatile short left_arm, volatile struct amber right_arm); + // cxx20-warning@-1 {{volatile-qualified parameter type 'volatile short' is deprecated}} + // cxx20-warning@-1 {{volatile-qualified parameter type 'volatile struct amber' is deprecated}} + void fly(volatile struct pterosaur* pteranodon); } namespace ArithConv { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits