Skip to content

Commit

Permalink
[clang] Fix -Wdeprecated-volatile for class types
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Oct 9, 2024
1 parent e637a5c commit 03ecd7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5019,12 +5019,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
} 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.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CXX/expr/expr.const/p2-0x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,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}}
}
Expand Down
7 changes: 7 additions & 0 deletions clang/test/SemaCXX/deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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@-2{{volatile-qualified parameter type 'volatile struct amber' is deprecated}}
void fly(volatile struct pterosaur* pteranodon);
}

namespace ArithConv {
Expand Down

0 comments on commit 03ecd7e

Please sign in to comment.