Skip to content

Commit 0b9c63d

Browse files
halbi2cor3ntin
andauthored
[clang] Warn about deprecated volatile-qualified return types (llvm#137899)
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 llvm#133380 Co-authored-by: cor3ntin <[email protected]>
1 parent 98d68e4 commit 0b9c63d

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ Improvements to Clang's diagnostics
509509
- Clang now prints the namespace for an attribute, if any,
510510
when emitting an unknown attribute diagnostic.
511511

512+
- ``-Wvolatile`` now warns about volatile-qualified class return types
513+
as well as volatile-qualified scalar return types. Fixes #GH133380
514+
512515
- Several compatibility diagnostics that were incorrectly being grouped under
513516
``-Wpre-c++20-compat`` are now part of ``-Wc++20-compat``. (#GH138775)
514517

@@ -921,7 +924,8 @@ Improvements
921924
^^^^^^^^^^^^
922925

923926
Additional Information
924-
======================
927+
928+
===================
925929

926930
A wide variety of additional information is available on the `Clang web
927931
page <https://clang.llvm.org/>`_. The web page contains versions of the

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)