Skip to content

-Wdeprecated-volatile doesn't handle class types correctly #39

@Quuxplusone

Description

@Quuxplusone

https://godbolt.org/z/r9o1b9qM8
https://eel.is/c++draft/depr.volatile.type#3 gives this Annex C example:

volatile struct amber jurassic();                               // deprecated
void trex(volatile short left_arm, volatile short right_arm);   // deprecated
void fly(volatile struct pterosaur* pteranodon);                // OK

Clang trunk diagnoses the second line, but not the first. This is because the line of code that emits that volatile-return-type warning:

    // 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;

is incorrectly placed inside this conditional:

if ((T.getCVRQualifiers() || T->isAtomicType()) &&
    !(S.getLangOpts().CPlusPlus &&
      (T->isDependentType() || T->isRecordType()))) {

instead of outside, so it incorrectly fails to apply to volatile-qualified class types such as struct amber.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions