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

    <tr>
        <th>Summary</th>
        <td>
            "pragma diagnostic ignored" not working as expected.
        </td>
    </tr>

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

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

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

<pre>
    Using LLVM 18 to build a.cpp, the`#pragma clang diagnostic ignored` could not silence the error. 

I haven't tested with all LLVM versions, but older versions of LLVM don't have this problem, as our code compiles correctly on older versions of LLVM.

```
/opt/homebrew/Cellar/llvm/18.1.8/bin/clang++ -Iopt/homebrew/Cellar/llvm/18.1.8 -Werror -std=c++17 -stdlib=libc++ -c a.cpp
```

```C++
// a.cpp

#include <codecvt>
#include <string>
#include <locale>

std::string ValidUtf8(const std::u16string &text) {
  std::u16string valid_substr;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conversion;
  return conversion.to_bytes(valid_substr);
#pragma clang diagnostic pop
}

int main(int argc, const char * argv[]) {
 return 0;
}
```

```
/opt/homebrew/Cellar/llvm/18.1.8/bin/../include/c++/v1/locale:3257:1: error: 'wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>' is deprecated [-Werror,-Wdeprecated-declarations]
 3257 | wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::to_bytes(const _Elem* __frm, const _Elem* __frm_end) {
      | ^
/opt/homebrew/Cellar/llvm/18.1.8/bin/../include/c++/v1/locale:3161:12: note: in instantiation of member function 'std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>::to_bytes' requested here
 3161 |     return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());
      | ^
/Users/bytedance/Desktop/a.cpp:10:21: note: in instantiation of member function 'std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>::to_bytes' requested here
   10 |   return conversion.to_bytes(valid_substr);
      | ^
/opt/homebrew/Cellar/llvm/18.1.8/bin/../include/c++/v1/locale:3114:28: note: 'wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>' has been explicitly marked deprecated here
 3114 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert {
      | ^
/opt/homebrew/Cellar/llvm/18.1.8/bin/../include/c++/v1/__config:1001:41: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX17'
 1001 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
      | ^
/opt/homebrew/Cellar/llvm/18.1.8/bin/../include/c++/v1/__config:974:49: note: expanded from macro '_LIBCPP_DEPRECATED'
  974 | #      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV1tv2zgT_TX0yyCCREmW9eAHxxcgQPoh-La3N4EiRza3FOmSlFPvr19QUnxJk25RtF2sYAjWkDM-c-bMmGLOya1GnJP8luSrCev8ztj54-djww7GTmojjvN3Tuot3N-_fwPJDLyBupNKAIv4fk_oEvwOyTQmNN1btm0ZcMX0FoRkW22clxzkVhuLgkxj4KZTArTx4KRCzTF4A1prbAQkXpF4MdzvYMcOqAktPHh0HgU8Sr8DptQA5YDWSaNdQFB3HowSaE9WMM2wTZghRogGficd7K2pFbbBjzkwnQVuBAI37V4qdMCNtci9OoLRr0SNLpGG3IfP8Eg3Zu8J3exMi7XFR0I3S1SKWUI3Sh1aQjfJLEqiGaGbWmpCNz1hhN4Segs3d9_pDTcfetrgxnlB0hUfAiRFb1CyJulKyZo_xeVjwV7EfG1cDj6nfAjdXDmP9lRqrjqBQNJloJAfPEnXL606b6XevrKoDGcKz4v9vc9pQdLF4ArvmZLinW9mhM640c7DaUeXTMdNhE49fvGElkCKET68tPEQol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