<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55338>55338</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Some C++20 deprecation warnings reported with -std=c++20 are not reported with -std=c++17 -Wc++20-compat or -Weverything
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          cpeterso
      </td>
    </tr>
</table>

<pre>
    Some C++20 deprecation warnings reported with `-std=c++20` are not reported with `-std=c++17 -Wc++20-compat` or `-Weverything`.

The following diagnostics are no-ops unless also compiled with -std=c++20:

-Wambiguous-reversed-operator
-Wdeprecated-pragma 
-Wdeprecated-this-capture
-Wdeprecated-volatile

This makes `-Wc++20-compat` not very useful.

### Steps to reproduce

Compare the output of compiling the following program with `clang++ -std=c++17 -Weverything` and then `clang++ -std=c++20 -Weverything`:

```
#include <atomic>

struct A {
  volatile int x;

  void test() {
    std::atomic<int> a = ATOMIC_VAR_INIT(1); // -Wdeprecated-pragma with -std=c++20

    [=]() {
      x; // -Wdeprecated-this-capture with -std=c++20 plus -Wdeprecated-this-capture or -Weverything
      x++; // -Wdeprecated-volatile with -std=c++20
    }();
  }

  bool operator==(const A& rhs) /* const */ { return x == rhs.x; } // -Wambiguous-reversed-operator with -std=c++20
};

int main() {
  A{} == A{};
  return 0;
}
```

### Expected behavior

I would expect that compiling the program with `clang++ -std=c++17 -Weverything` (or `clang++ -std=c++17 -Wc++20-compat`, `clang++ -std=c++17 -Wc++20-compat-pedantic`, or `clang++ -std=c++17 -Wambiguous-reversed-operator -Wdeprecated-pragma -Wdeprecated-this-capture -Wdeprecated-volatile`) would report the same warnings as compiling with `clang++ -std=c++20 -Weverything`.

### Actual behavior

Compiling the program with `clang++ -std=c++17 -Weverything` reports no warnings, but compiling with `clang++ -Weverything -std=c++20`will report four warnings:

```
test.cpp:7:26: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
    std::atomic<int> a = ATOMIC_VAR_INIT(1); // -Wdeprecated-pragma with -std=c++20
                         ^
/Users/chris/.mozbuild/clang/bin/../include/c++/v1/atomic:2709:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
test.cpp:11:8: warning: increment of object of volatile-qualified type 'volatile int' is deprecated [-Wdeprecated-volatile]
      x++; // -Wdeprecated-volatile with -std=c++20
       ^
test.cpp:10:7: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]
      x; // -Wdeprecated-this-capture with -std=c++20 plus -Wdeprecated-this-capture or -Weverything
      ^
test.cpp:9:6: note: add an explicit capture of 'this' to capture '*this' by reference
    [=]() {
     ^
      , this
test.cpp:19:7: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'A' and 'A') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
  A{} == A{};
  ~~~ ^  ~~~
test.cpp:15:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
  bool operator==(const A& rhs) /* const */ { return x == rhs.x; } // -Wambiguous-reversed-operator with -std=c++20
       ^
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVV1mP2zYQ_jXyy8CGLPl88IPXmwX2oQ3QpM1jQIm0zYYWFR7rbH99Z6jDsq21gzRA0IVWljjkHN-cyjR_XX3QBwGbKHnAK4mBi9KInDmpCzgyU8hiZ8GIUhsnOByl20M0i4fW8Sh9zJtjuATMCCi0u7d5PIfhp_bgMNeHkjk6r03Y_Em8CPPq9igYX0dR_BjF6-r-cS9gq5XSRyQCl2xXaOtkbmvZQ11a8IUSFleU1UDMpWpUuVI6XXe5Dz-xQyZ3Xns7NKSEFRw5CsOcNs2WBh4klYbtDgx6KKi8HeasdN6IHvKLVoivEuemSQsH9kXYCoQ-gAhcwga8FVuvzqCJkrS64IMTiILT5Aeju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