Skip to content

Commit 41feb9b

Browse files
committed
[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
1 parent 82ab359 commit 41feb9b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ Improvements to Clang's diagnostics
420420
the ``-Wc99-designator`` diagnostic group, as they also are about the
421421
behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
422422

423+
- ``-Wvolatile`` now warns about volatile-qualified class return types
424+
as well as volatile-qualified scalar return types. Fixes #GH133380
425+
423426
Improvements to Clang's time-trace
424427
----------------------------------
425428

clang/lib/Sema/SemaType.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,13 +5056,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
50565056
S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T;
50575057
} else
50585058
diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
5059-
5060-
// C++2a [dcl.fct]p12:
5061-
// A volatile-qualified return type is deprecated
5062-
if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20)
5063-
S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T;
50645059
}
50655060

5061+
// C++2a [dcl.fct]p12:
5062+
// A volatile-qualified return type is deprecated
5063+
if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20)
5064+
S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T;
5065+
50665066
// Objective-C ARC ownership qualifiers are ignored on the function
50675067
// return type (by type canonicalization). Complain if this attribute
50685068
// was written here.

clang/test/CXX/expr/expr.const/p2-0x.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ namespace LValueToRValue {
356356
// - a non-volatile glvalue of literal type that refers to a non-volatile
357357
// temporary object whose lifetime has not ended, initialized with a
358358
// constant expression;
359-
constexpr volatile S f() { return S(); }
359+
constexpr volatile S f() { return S(); } // cxx20-warning {{volatile-qualified return type 'volatile S' is deprecated}}
360360
static_assert(f().i, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}}
361361
static_assert(((volatile const S&&)(S)0).i, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}}
362362
}

clang/test/SemaCXX/deprecated.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ namespace DeprecatedVolatile {
231231
a = c = a;
232232
b += a;
233233
}
234+
235+
volatile struct amber jurassic();
236+
// cxx20-warning@-1 {{volatile-qualified return type 'volatile struct amber' is deprecated}}
237+
void trex(volatile short left_arm, volatile struct amber right_arm);
238+
// cxx20-warning@-1 {{volatile-qualified parameter type 'volatile short' is deprecated}}
239+
// cxx20-warning@-2 {{volatile-qualified parameter type 'volatile struct amber' is deprecated}}
240+
void fly(volatile struct pterosaur* pteranodon);
234241
}
235242

236243
namespace ArithConv {

0 commit comments

Comments
 (0)