Skip to content

[clang] Warn about deprecated volatile-qualified return types #137899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is another place that issues warn_deprecated_volatile_return in Sema::CheckFunctionReturnType. I wonder why doesn't it suffice?


// 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 @@ -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}}
}
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I can see, if the return type is not a struct/class, the warning is issued. Could you please add a test case with volatile qualifier applied to a basic type (for example int) and make sure there is no double diagnostic issued now?

// 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 {
Expand Down
Loading