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

    <tr>
        <th>Summary</th>
        <td>
            Disabling deprecation warnings for templated classes at call site not working
        </td>
    </tr>

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

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

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

<pre>
    ```
#if defined(_MSC_VER)
#define WARNING_DISABLE_DEPRECATED __pragma(warning(disable : 4947 4995 4996))
#elif defined(__clang__)
#define WARNING_DISABLE_DEPRECATED \
        _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#else // gcc
#define WARNING_DISABLE_DEPRECATED \
        _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#endif

// Test.hpp
template<class T>
struct Test {
    Test() = default; 
    T member;
};

// FooAndFriends.hpp
struct Foo {
 [[deprecated]] Foo() {}
    explicit Foo(int i) : m_i(i) {}
    int m_i = 0;
};
    
[[deprecated]] inline void bar() {
 WARNING_DISABLE_DEPRECATED
    auto no_warning = Foo();
    auto warning = Test<Foo>();
}
```

This is a reduced sample for msvc, clang, and gcc (removed pragma push/pop for brevity and moved code from multiple files into one).

We want to deprecate the default constructor of `Foo` and the free function `bar()`. Users should receive warnings when calling them, but not when including the headers. The problem is that `bar()` uses the deprecated constructor indirectly through the template class `Test`, which will trigger a warning if someone includes the header. Therefore we want to disable the deprecation warning inside of `bar()`, to avoid warnings on include.

Compiling this code with gcc trunk and clang trunk with godbolt outputs a warning, even though `WARNING_DISABLE_DEPRECATED` is specified. Clang output:

```
<source>:14:5: warning: 'Foo' is deprecated [-Wdeprecated-declarations]
   14 |     Test() = default; 
      |     ^
<source>:28:20: note: in defaulted default constructor for 'Test<Foo>' first required here
   28 |     auto warning = Test<Foo>();
      |                    ^
<source>:20:7: note: 'Foo' has been explicitly marked deprecated here
   20 |     [[deprecated]] Foo() {}
      |       ^
```

It even correctly identifies the offending code (line 28, "first required here").
To "fix" this error, one has to do one of the following:

1. Add WARNING_DISABLE_DEPRECATED around the default constructor of `Test`.
2. Add WARNING_DISABLE_DEPRECATED around the include to `Test.hpp`.

`1` is not always possible with external sources. And I don't see why `Test` should change if its unrelated to `Foo`.
`2` is doable but also problematic. It would need extra documentation on why this warning disable macro is around `Test.hpp` instead of the offending code. And it could hide other actual warnings, such as further unwanted usages of `Test<Foo>()`.

Compiling this code under msvc does the (in my opinion) expected thing, of not issuing a warning anymore for `Test<Foo>()`, if the warning is disabled at the callsite.

Is this considered a bug? Is this known and expected?
Is there some other workaround to disable this warning locally, only for the line containing `Test<Foo>()`?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV12P4joS_TXmpTQoOHw-8EBDc9XS7tXV3N6dR2TsCvFtx2Ztpxn-_arsBEJvz2hHuiOUoeOy69THOWVECPpkEdds9sRmu5FoY-38-i9X28oL-2a09Vq-Ca9GR6euazYvuk-xY8WG8VJXoLDSFhXjy8M__9we_v38lfHVzSCvwrfN199ffv_tsHv5c_P0j-fD7vmPr8_bzevzDg6HsxenRjC-vAhvtT0xvlQ6iKNBYOUGpqvpAqar1Yweczp8cD6aRwgHaYQ9HQ6_hoHNtp11sTr80cNhnKfTQGlxsi5ELUGfrPOo0g7Ov3xTePYoRUT1RaE0wouonQ15OX2GWAMC43vG93CS8u_A99t2-7ehs0pXvZf8LiF9xRDH9fmcX0ZszkZEZOVWGhECvLLyOS-F6FsZkz2wxVN-CQDpTYK7AlbuqFqiNZGVTzCwgQabI3pWdhvZYnf_PsSzd25j1d5rtCrcgXXe984NnKe-frpngc12bLYjox7P4okc3WDg97PRUsfORNsIOuPeQHPQ9OqzbWTXHHQKr_g0BLLq3n6OSVtDTfDutIKj8AN8ef-Pu-PuQLTRgXWHjkcJzi3WByjJcmiWalRuybp8_rDhFupH_qfna60D6AACPKpWooIgmr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