[libcxx-commits] [libcxx] [libc++] Only push/pop diagnostics for ABI annotations pragmas if not in a system header (PR #200338)

Alexey Samsonov via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 5 11:49:51 PDT 2026


vonosmas wrote:

It looks like after this change the diagnostic is suppressed for libc++ headers (since they all use `#pragma GCC system_header`), but not for the source files that use namespace macro - that is -- we observe the problems when building libc++ library itself:

```
/libcxx/src/fstream.cpp:20:1: error: unused attribute '__exclude_from_explicit_instantiation__' in '#pragma clang attribute push' region [-Werror,-Wpragma-clang-attribute]
   20 | _LIBCPP_BEGIN_NAMESPACE_STD
      | ^
/libcxx/include/__configuration/namespace.h:71:39: note: expanded from macro '_LIBCPP_BEGIN_NAMESPACE_STD'
   71 | #  define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE {
      |                                       ^
/libcxx/include/__configuration/namespace.h:67:40: note: expanded from macro '_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD'
   67 |     _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS _LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
      |                                        ^
/libcxx/include/__configuration/namespace.h:50:3: note: expanded from macro '_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS'
   50 |   _Pragma(_LIBCPP_TOSTRING(clang attribute _LibcxxExplicitABIAnnotations.push(                                         \
      |   ^
<scratch space>:41:69: note: expanded from here
   41 |  clang attribute _LibcxxExplicitABIAnnotations.push( __attribute__((__exclude_from_explicit_instantiation__)), apply_to = function)
```

I don't think there's an easy way to determine if we're building the library, and have tighter control over when diagnostic should be enabled (besides compile flags for CMake project / downstream libc++ build)?

https://github.com/llvm/llvm-project/pull/200338


More information about the libcxx-commits mailing list