On Thu, 26 Feb 2026 04:42:17 GMT, Kim Barrett <[email protected]> wrote:
> This is a gcc12-specific glibc bug. > > gcc11.5 does not annotate get_temporary_buffer with the _GLIBCXX17_DEPRECATED > attribute. > > gcc12.2 adds the deprecated attribute to `get_temporary_buffer`. > > gcc13.2 and later continue to have the deprecated attribute, but also disable > that warning around the call down in the guts of `stable_sort`. > > I wasn't able to reproduce the warning when building with our gcc12.2 devkit. > That's because the relevant headers are treated as system headers, so the > warning is suppressed. (Verified by turning on `-Wsystem-headers` while > building gtest.) > > So why isn't clang treating the relevant headers as system headers in the > configuration where this warning is arising? > > I don't think an unconditional clang disabling of the warning for the gtest > build is an appropriate fix. The libstdc++ API [document](https://gcc.gnu.org/onlinedocs/libstdc++/manual/api.html) says `get_temporary_buffer` was duplicated since gcc12 for C++17. I can reproduce the `deprecated-declarations` warning with gcc12 by turning on `-Wsystem-headers`. By default, gcc12 will not generate the deprecated warning, because `-Wsystem-headers` is disable by default(grep system-headers return nothing). yansendao@zhangfei:[jdk]> g++ -std=c++17 -Wall -Wextra -I/home/yansendao/git/googletest-v1.14.0/googletest -I/home/yansendao/git/googletest-v1.14.0/googletest/include -Werror -O3 -c gtest-all.cc ; echo $? 0 yansendao@zhangfei:[jdk]> g++ -std=c++17 -Wall -Wextra -I/home/yansendao/git/googletest-v1.14.0/googletest -I/home/yansendao/git/googletest-v1.14.0/googletest/include -Werror -O3 -c gtest-all.cc -v 2>&1 | grep "system-headers" yansendao@zhangfei:[jdk]> echo $? 1 With enable -Wsystem-headers explictly, gcc12 will generate the deprecated warning, same to clang23. > g++ -std=c++17 -Wall -Wextra -Wsystem-headers > -I/home/yansendao/git/googletest-v1.14.0/googletest > -I/home/yansendao/git/googletest-v1.14.0/googletest/include -Werror -O3 -c > gtest-all.cc ; echo $? In file included from /home/yansendao/git/googletest-v1.14.0/googletest/include/gtest/internal/gtest-port.h:2460, from /home/yansendao/git/googletest-v1.14.0/googletest/include/gtest/gtest-message.h:57, from /home/yansendao/git/googletest-v1.14.0/googletest/include/gtest/gtest-assertion-result.h:46, from /home/yansendao/git/googletest-v1.14.0/googletest/include/gtest/gtest.h:64, from /home/yansendao/git/googletest-v1.14.0/googletest/src/gtest.cc:33, from gtest-all.cc:1: /usr/include/c++/12/variant:837:31: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers] 837 | struct __untag_result<const void(*)(_Args...)> | ^~~~~ In file included from /usr/include/c++/12/memory:66, from /home/yansendao/git/googletest-v1.14.0/googletest/include/gtest/gtest.h:56: /usr/include/c++/12/bits/stl_tempbuf.h: In instantiation of ‘std::_Temporary_buffer<_ForwardIterator, _Tp>::_Temporary_buffer(_ForwardIterator, size_type) [with _ForwardIterator = __gnu_cxx::__normal_iterator<testing::TestInfo**, std::vector<testing::TestInfo*> >; _Tp = testing::TestInfo*; size_type = long int]’: /usr/include/c++/12/bits/stl_algo.h:4996:15: required from ‘void std::__stable_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<testing::TestInfo**, vector<testing::TestInfo*> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<testing::TestSuite::Run()::<lambda(const testing::TestInfo*, const testing::TestInfo*)> >]’ /usr/include/c++/12/bits/stl_algo.h:5070:36: required from ‘void std::stable_sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<testing::TestInfo**, vector<testing::TestInfo*> >; _Compare = testing::TestSuite::Run()::<lambda(const testing::TestInfo*, const testing::TestInfo*)>]’ /home/yansendao/git/googletest-v1.14.0/googletest/src/gtest.cc:2986:19: required from here /usr/include/c++/12/bits/stl_tempbuf.h:263:54: error: ‘std::pair<_Tp*, long int> std::get_temporary_buffer(ptrdiff_t) [with _Tp = testing::TestInfo*; ptrdiff_t = long int]’ is deprecated [-Werror=deprecated-declarations] 263 | std::get_temporary_buffer<value_type>(_M_original_len)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /usr/include/c++/12/bits/stl_tempbuf.h:101:5: note: declared here 101 | get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOEXCEPT | ^~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors 1 The file gtest-all.cc is reduce from the original googletest/src/gtest-all.cc by creduce tools. It only contains one line. ```c++ > cat gtest-all.cc #include "src/gtest.cc" ------------- PR Comment: https://git.openjdk.org/jdk/pull/29919#issuecomment-3964543738
