On Tue, Oct 25, 2022 at 11:39:31AM -0400, Jason Merrill wrote: > On 10/25/22 09:14, Marek Polacek wrote: > > On Tue, Oct 25, 2022 at 12:34:50PM +0100, Jonathan Wakely wrote: > > > On Mon, 24 Oct 2022 at 18:30, Jason Merrill wrote: > > > > > > > > On 10/21/22 19:28, Marek Polacek wrote: > > > > > When testing a previous version of the patch, there were many FAILs in > > > > > libstdc++'s 22_locale/; all of them because the warning triggered on > > > > > > > > > > const test_type& obj = std::use_facet<test_type>(std::locale()); > > > > > > > > > > but this code looks valid -- std::use_facet doesn't return a reference > > > > > to its parameter. Therefore I added code to suppress the warning when > > > > > the call is std::use_facet. Now 22_locale/* pass even with the > > > > > warning > > > > > on. We could exclude more std:: functions like this if desirable. > > > > > > > > Instead of adding special cases in the compiler, let's disable the > > > > warning around the definition of use_facet (and adjust the compiler as > > > > needed so that avoids the warning). > > > > > > I assume you mean using #pragma here. If we disable it around the > > > definition of use_facet, will that disable it for callers of > > > use_facet, or only within the definition of use_facet itself? > > > > Right, a #pragma will not help, it would only disable the warning > > within the definition of use_facet itself. > > That's why I mentioned adjusting the compiler, i.e. check warning_enabled_at > (DECL_SOURCE_LOCATION (fn)
Ah, like with -Wdeprecated-copy. I think I fixed this: --- a/libstdc++-v3/include/bits/locale_classes.tcc +++ b/libstdc++-v3/include/bits/locale_classes.tcc @@ -127,6 +127,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return Reference to facet of type Facet. * @throw std::bad_cast if @p __loc doesn't contain a facet of type _Facet. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-reference" template<typename _Facet> const _Facet& use_facet(const locale& __loc) @@ -141,6 +143,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return static_cast<const _Facet&>(*__facets[__i]); #endif } +#pragma GCC diagnostic pop // Generic version does nothing. and then just check warning_enabled_at. Nice! Marek