diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 1bf98f74d459..29ecf15c7e39 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -2191,6 +2191,15 @@ ftms = { }; }; +ftms = { + name = is_implicit_lifetime; + values = { + v = 202302; + cxxmin = 23; + extra_cond = "__has_builtin(__builtin_is_implicit_lifetime)"; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 66de8b487e35..5901d27113d7 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2455,4 +2455,14 @@ #endif /* !defined(__cpp_lib_philox_engine) */ #undef __glibcxx_want_philox_engine +#if !defined(__cpp_lib_is_implicit_lifetime) +# if (__cplusplus >= 202100L) && (__has_builtin(__builtin_is_implicit_lifetime)) +# define __glibcxx_is_implicit_lifetime 202302L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_is_implicit_lifetime) +# define __cpp_lib_is_implicit_lifetime 202302L +# endif +# endif +#endif /* !defined(__cpp_lib_is_implicit_lifetime) */ +#undef __glibcxx_want_is_implicit_lifetime + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 77ebb7e2c2f9..d28b077398be 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -47,6 +47,7 @@ #define __glibcxx_want_is_aggregate #define __glibcxx_want_is_constant_evaluated #define __glibcxx_want_is_final +#define __glibcxx_want_is_implicit_lifetime #define __glibcxx_want_is_invocable #define __glibcxx_want_is_layout_compatible #define __glibcxx_want_is_nothrow_convertible @@ -4053,6 +4054,22 @@ template # endif #endif +#ifdef __cpp_lib_is_implicit_lifetime // C++ >= 23 + /// True if the type is an implicit-lifetime type. + /// @since C++23 + + template + struct is_implicit_lifetime + : bool_constant<__builtin_is_implicit_lifetime(_Tp)> + { }; + + /// @ingroup variable_templates + /// @since C++23 + template + inline constexpr bool is_implicit_lifetime_v + = __builtin_is_implicit_lifetime(_Tp); +#endif + #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp /// True if _Tp is a reference type, a _Up value can be bound to _Tp in /// direct-initialization, and a temporary object would be bound to diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in index 4c11b1bf7114..28f0e8cb1fb6 100644 --- a/libstdc++-v3/src/c++23/std.cc.in +++ b/libstdc++-v3/src/c++23/std.cc.in @@ -3230,6 +3230,10 @@ export namespace std using std::is_scoped_enum; using std::is_scoped_enum_v; #endif +#if __cpp_lib_is_implicit_lifetime + using std::is_implicit_lifetime; + using std::is_implicit_lifetime_v; +#endif } // diff --git a/libstdc++-v3/testsuite/20_util/is_implicit_lifetime/value.cc b/libstdc++-v3/testsuite/20_util/is_implicit_lifetime/value.cc new file mode 100644 index 000000000000..d8cb181e9af4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_implicit_lifetime/value.cc @@ -0,0 +1,129 @@ +// Copyright (C) 2025 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_is_implicit_lifetime +# error "Feature test macro for is_implicit_lifetime is missing in " +#elif __cpp_lib_is_implicit_lifetime < 202302L +# error "Feature test macro for is_implicit_lifetime has wrong value in " +#endif + +#include + +template + concept Is_implicit_lifetime + = __gnu_test::test_category(true); + +static_assert( ! Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +enum W { W1 }; +static_assert( Is_implicit_lifetime ); +enum class X : int { X1 }; +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +struct Y { int g; int foo (int); }; +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +static_assert( ! Is_implicit_lifetime ); +struct Z; +static_assert( Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +struct A { int a, b, c; }; +static_assert( Is_implicit_lifetime ); +class B { static int a; private: static int b; public: int c; }; +static_assert( Is_implicit_lifetime ); +struct C { C () {} int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct D { explicit D (int) {} int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct E : public A { int d, e, f; }; +static_assert( Is_implicit_lifetime ); +struct F : public C { using C::C; int d, e, f; }; +static_assert( Is_implicit_lifetime ); +class G { int a, b; }; +static_assert( Is_implicit_lifetime ); +struct H { private: int a, b; }; +static_assert( Is_implicit_lifetime ); +struct I { protected: int a, b; }; +static_assert( Is_implicit_lifetime ); +struct J { int a, b; void foo (); }; +static_assert( Is_implicit_lifetime ); +struct K { int a, b; virtual void foo (); }; +static_assert( ! Is_implicit_lifetime ); +struct L : virtual public A { int d, e; }; +static_assert( ! Is_implicit_lifetime ); +struct M : protected A { int d, e; }; +static_assert( Is_implicit_lifetime ); +struct N : private A { int d, e; }; +static_assert( Is_implicit_lifetime ); +struct O { O () = delete; int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct P { P () = default; int a, b, c; }; +static_assert( Is_implicit_lifetime

); +struct Q { Q (); Q (const Q &); int a, b, c; }; +static_assert( ! Is_implicit_lifetime ); +struct R { R (); R (const R &); R (R &&) = default; int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct S { S (); ~S (); int a, b, c; }; +static_assert( ! Is_implicit_lifetime ); +static_assert( Is_implicit_lifetime ); +struct T { T (); ~T () = default; int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct U { U (); U (const U &) = default; int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct V { V () = default; V (const V &); int a, b, c; }; +static_assert( Is_implicit_lifetime ); +struct AA { Q a; Q b; }; +static_assert( Is_implicit_lifetime ); +struct AB { Q a; Q b; ~AB () = default; }; +static_assert( Is_implicit_lifetime ); +struct AC { Q a; Q b; ~AC () {} }; +static_assert( ! Is_implicit_lifetime ); +struct AD : public Q {}; +static_assert( Is_implicit_lifetime ); +struct AE : public Q { ~AE () = default; }; +static_assert( Is_implicit_lifetime ); +struct AF : public Q { ~AF () {} }; +static_assert( ! Is_implicit_lifetime ); diff --git a/libstdc++-v3/testsuite/20_util/is_implicit_lifetime/version.cc b/libstdc++-v3/testsuite/20_util/is_implicit_lifetime/version.cc new file mode 100644 index 000000000000..ed90b47c8662 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_implicit_lifetime/version.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2025 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_is_implicit_lifetime +# error "Feature test macro for is_implicit_lifetime is missing in " +#elif __cpp_lib_is_implicit_lifetime < 202302L +# error "Feature test macro for is_implicit_lifetime has wrong value in " +#endif