Skip to content

Commit 0a13175

Browse files
authored
[libc++] Adds a global private constructor tag. (llvm#87920)
This removes the similar tags used in the chrono tzdb implementation. Fixes: llvm#85432
1 parent 2b00a73 commit 0a13175

File tree

20 files changed

+79
-103
lines changed

20 files changed

+79
-103
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ set(files
863863
__utility/pair.h
864864
__utility/piecewise_construct.h
865865
__utility/priority_tag.h
866+
__utility/private_constructor_tag.h
866867
__utility/rel_ops.h
867868
__utility/small_buffer.h
868869
__utility/swap.h

libcxx/include/__chrono/leap_second.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# include <__compare/ordering.h>
2323
# include <__compare/three_way_comparable.h>
2424
# include <__config>
25+
# include <__utility/private_constructor_tag.h>
2526

2627
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2728
# pragma GCC system_header
@@ -35,9 +36,8 @@ namespace chrono {
3536

3637
class leap_second {
3738
public:
38-
struct __constructor_tag;
3939
[[nodiscard]]
40-
_LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__constructor_tag&&, sys_seconds __date, seconds __value)
40+
_LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__private_constructor_tag, sys_seconds __date, seconds __value)
4141
: __date_(__date), __value_(__value) {}
4242

4343
_LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default;

libcxx/include/__chrono/time_zone_link.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# include <__compare/strong_order.h>
2020
# include <__config>
21+
# include <__utility/private_constructor_tag.h>
2122
# include <string>
2223
# include <string_view>
2324

@@ -37,9 +38,8 @@ namespace chrono {
3738

3839
class time_zone_link {
3940
public:
40-
struct __constructor_tag;
4141
_LIBCPP_NODISCARD_EXT
42-
_LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__constructor_tag&&, string_view __name, string_view __target)
42+
_LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__private_constructor_tag, string_view __name, string_view __target)
4343
: __name_{__name}, __target_{__target} {}
4444

4545
_LIBCPP_HIDE_FROM_ABI time_zone_link(time_zone_link&&) = default;

libcxx/include/__locale

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <__mutex/once_flag.h>
1717
#include <__type_traits/make_unsigned.h>
1818
#include <__utility/no_destroy.h>
19+
#include <__utility/private_constructor_tag.h>
1920
#include <cctype>
2021
#include <clocale>
2122
#include <cstdint>
@@ -97,8 +98,7 @@ private:
9798

9899
template <class>
99100
friend struct __no_destroy;
100-
struct __private_tag {};
101-
_LIBCPP_HIDE_FROM_ABI explicit locale(__private_tag, __imp* __loc) : __locale_(__loc) {}
101+
_LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {}
102102

103103
void __install_ctor(const locale&, facet*, long);
104104
static locale& __global();
@@ -1248,10 +1248,10 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char
12481248
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12491249
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
12501250
#endif
1251-
extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
1252-
codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1253-
extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
1254-
codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1251+
extern template class _LIBCPP_DEPRECATED_IN_CXX20
1252+
_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1253+
extern template class _LIBCPP_DEPRECATED_IN_CXX20
1254+
_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
12551255
#ifndef _LIBCPP_HAS_NO_CHAR8_T
12561256
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
12571257
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20

libcxx/include/__stop_token/stop_callback.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <__type_traits/is_nothrow_constructible.h>
2222
#include <__utility/forward.h>
2323
#include <__utility/move.h>
24+
#include <__utility/private_constructor_tag.h>
2425

2526
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2627
# pragma GCC system_header
@@ -49,13 +50,13 @@ class _LIBCPP_AVAILABILITY_SYNC stop_callback : private __stop_callback_base {
4950
requires constructible_from<_Callback, _Cb>
5051
_LIBCPP_HIDE_FROM_ABI explicit stop_callback(const stop_token& __st,
5152
_Cb&& __cb) noexcept(is_nothrow_constructible_v<_Callback, _Cb>)
52-
: stop_callback(__private_tag{}, __st.__state_, std::forward<_Cb>(__cb)) {}
53+
: stop_callback(__private_constructor_tag{}, __st.__state_, std::forward<_Cb>(__cb)) {}
5354

5455
template <class _Cb>
5556
requires constructible_from<_Callback, _Cb>
5657
_LIBCPP_HIDE_FROM_ABI explicit stop_callback(stop_token&& __st,
5758
_Cb&& __cb) noexcept(is_nothrow_constructible_v<_Callback, _Cb>)
58-
: stop_callback(__private_tag{}, std::move(__st.__state_), std::forward<_Cb>(__cb)) {}
59+
: stop_callback(__private_constructor_tag{}, std::move(__st.__state_), std::forward<_Cb>(__cb)) {}
5960

6061
_LIBCPP_HIDE_FROM_ABI ~stop_callback() {
6162
if (__state_) {
@@ -74,10 +75,8 @@ class _LIBCPP_AVAILABILITY_SYNC stop_callback : private __stop_callback_base {
7475

7576
friend __stop_callback_base;
7677

77-
struct __private_tag {};
78-
7978
template <class _StatePtr, class _Cb>
80-
_LIBCPP_HIDE_FROM_ABI explicit stop_callback(__private_tag, _StatePtr&& __state, _Cb&& __cb) noexcept(
79+
_LIBCPP_HIDE_FROM_ABI explicit stop_callback(__private_constructor_tag, _StatePtr&& __state, _Cb&& __cb) noexcept(
8180
is_nothrow_constructible_v<_Callback, _Cb>)
8281
: __stop_callback_base([](__stop_callback_base* __cb_base) noexcept {
8382
// stop callback is supposed to only be called once
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP__UTILITY_PRIVATE_CONSTRUCTOR_TAG_H
11+
#define _LIBCPP__UTILITY_PRIVATE_CONSTRUCTOR_TAG_H
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
// This tag allows defining non-standard exposition-only constructors while
22+
// preventing users from being able to use them, since this reserved-name tag
23+
// needs to be used.
24+
struct __private_constructor_tag {};
25+
26+
_LIBCPP_END_NAMESPACE_STD
27+
28+
#endif // _LIBCPP__UTILITY_PRIVATE_CONSTRUCTOR_TAG_H

libcxx/include/module.modulemap

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,18 +2090,19 @@ module std_private_utility_pair [system] {
20902090
export std_private_type_traits_is_nothrow_move_assignable
20912091
export std_private_utility_pair_fwd
20922092
}
2093-
module std_private_utility_pair_fwd [system] { header "__fwd/pair.h" }
2094-
module std_private_utility_piecewise_construct [system] { header "__utility/piecewise_construct.h" }
2095-
module std_private_utility_priority_tag [system] { header "__utility/priority_tag.h" }
2096-
module std_private_utility_rel_ops [system] { header "__utility/rel_ops.h" }
2097-
module std_private_utility_small_buffer [system] { header "__utility/small_buffer.h" }
2098-
module std_private_utility_swap [system] {
2093+
module std_private_utility_pair_fwd [system] { header "__fwd/pair.h" }
2094+
module std_private_utility_piecewise_construct [system] { header "__utility/piecewise_construct.h" }
2095+
module std_private_utility_priority_tag [system] { header "__utility/priority_tag.h" }
2096+
module std_private_utility_private_constructor_tag [system] { header "__utility/private_constructor_tag.h" }
2097+
module std_private_utility_rel_ops [system] { header "__utility/rel_ops.h" }
2098+
module std_private_utility_small_buffer [system] { header "__utility/small_buffer.h" }
2099+
module std_private_utility_swap [system] {
20992100
header "__utility/swap.h"
21002101
export std_private_type_traits_is_swappable
21012102
}
2102-
module std_private_utility_to_underlying [system] { header "__utility/to_underlying.h" }
2103-
module std_private_utility_unreachable [system] { header "__utility/unreachable.h" }
2103+
module std_private_utility_to_underlying [system] { header "__utility/to_underlying.h" }
2104+
module std_private_utility_unreachable [system] { header "__utility/unreachable.h" }
21042105

2105-
module std_private_variant_monostate [system] { header "__variant/monostate.h" }
2106+
module std_private_variant_monostate [system] { header "__variant/monostate.h" }
21062107

2107-
module std_private_vector_fwd [system] { header "__fwd/vector.h" }
2108+
module std_private_vector_fwd [system] { header "__fwd/vector.h" }

libcxx/src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ endif()
334334

335335
if (LIBCXX_ENABLE_LOCALIZATION AND LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_ENABLE_TIME_ZONE_DATABASE)
336336
list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
337-
include/tzdb/leap_second_private.h
338-
include/tzdb/time_zone_link_private.h
339337
include/tzdb/time_zone_private.h
340338
include/tzdb/types_private.h
341339
include/tzdb/tzdb_list_private.h

libcxx/src/include/tzdb/leap_second_private.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

libcxx/src/include/tzdb/time_zone_link_private.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

libcxx/src/locale.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ constinit __no_destroy<locale::__imp>
497497
locale::__imp::classic_locale_imp_(__uninitialized_tag{}); // initialized below in classic()
498498

499499
const locale& locale::classic() {
500-
static const __no_destroy<locale> classic_locale(__private_tag{}, [] {
500+
static const __no_destroy<locale> classic_locale(__private_constructor_tag{}, [] {
501501
// executed exactly once on first initialization of `classic_locale`
502502
locale::__imp::classic_locale_imp_.__emplace(1u);
503503
return &locale::__imp::classic_locale_imp_.__get();

libcxx/src/tzdb.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <stdexcept>
1616
#include <string>
1717

18-
#include "include/tzdb/leap_second_private.h"
19-
#include "include/tzdb/time_zone_link_private.h"
2018
#include "include/tzdb/time_zone_private.h"
2119
#include "include/tzdb/types_private.h"
2220
#include "include/tzdb/tzdb_list_private.h"
@@ -582,7 +580,7 @@ static void __parse_link(tzdb& __tzdb, istream& __input) {
582580
string __name = chrono::__parse_string(__input);
583581
chrono::__skip_line(__input);
584582

585-
__tzdb.links.emplace_back(time_zone_link::__constructor_tag{}, std::move(__name), std::move(__target));
583+
__tzdb.links.emplace_back(std::__private_constructor_tag{}, std::move(__name), std::move(__target));
586584
}
587585

588586
static void __parse_tzdata(tzdb& __db, __tz::__rules_storage_type& __rules, istream& __input) {
@@ -649,7 +647,7 @@ static void __parse_leap_seconds(vector<leap_second>& __leap_seconds, istream&&
649647
seconds __value{chrono::__parse_integral(__input, false)};
650648
chrono::__skip_line(__input);
651649

652-
__leap_seconds.emplace_back(leap_second::__constructor_tag{}, __date, __value);
650+
__leap_seconds.emplace_back(std::__private_constructor_tag{}, __date, __value);
653651
}
654652
}
655653

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// struct __private_constructor_tag{};
10+
11+
// The private constructor tag is intended to be a trivial type that can easily
12+
// be used to mark a constructor exposition-only.
13+
//
14+
// Tests whether the type is trivial.
15+
16+
#include <__utility/private_constructor_tag.h>
17+
#include <type_traits>
18+
19+
static_assert(std::is_trivial<std::__private_constructor_tag>::value, "");

libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <type_traits>
2828
#include <cassert>
2929

30-
// Add the include path required by test_chrono_leap_second.h when using libc++.
31-
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %{libcxx-dir}/src/include
3230
#include "test_chrono_leap_second.h"
3331

3432
constexpr bool test() {

libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <concepts>
2626
#include <cassert>
2727

28-
// Add the include path required by test_chrono_leap_second.h when using libc++.
29-
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %{libcxx-dir}/src/include
3028
#include "test_chrono_leap_second.h"
3129

3230
constexpr bool test() {

libcxx/test/std/time/time.zone/time.zone.leap/members/date.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
#include "test_macros.h"
2525

26-
// Add the include path required by test_chrono_leap_second.h when using libc++.
27-
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %{libcxx-dir}/src/include
2826
#include "test_chrono_leap_second.h"
2927

3028
constexpr void test(const std::chrono::leap_second leap_second, std::chrono::sys_seconds expected) {

libcxx/test/std/time/time.zone/time.zone.leap/members/value.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
#include "test_macros.h"
2525

26-
// Add the include path required by test_chrono_leap_second.h when using libc++.
27-
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %{libcxx-dir}/src/include
2826
#include "test_chrono_leap_second.h"
2927

3028
constexpr void test(const std::chrono::leap_second leap_second, std::chrono::seconds expected) {

libcxx/test/std/time/time.zone/time.zone.leap/nonmembers/comparison.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
#include "test_macros.h"
5151
#include "test_comparisons.h"
5252

53-
// Add the include path required by test_chrono_leap_second.h when using libc++.
54-
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %{libcxx-dir}/src/include
5553
#include "test_chrono_leap_second.h"
5654

5755
constexpr void test_comparison(const std::chrono::leap_second lhs, const std::chrono::leap_second rhs) {

libcxx/test/support/test_chrono_leap_second.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,11 @@
3232

3333
#ifdef _LIBCPP_VERSION
3434

35-
// In order to find this include the calling test needs to provide this path in
36-
// the search path. Typically this looks like:
37-
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %{libcxx-dir}/src/include
38-
// where the number of `../` sequences depends on the subdirectory level of the
39-
// test.
40-
# include "tzdb/leap_second_private.h" // Header in the dylib
35+
# include <__utility/private_constructor_tag.h>
4136

4237
inline constexpr std::chrono::leap_second
4338
test_leap_second_create(const std::chrono::sys_seconds& date, const std::chrono::seconds& value) {
44-
return std::chrono::leap_second{std::chrono::leap_second::__constructor_tag{}, date, value};
39+
return std::chrono::leap_second{std::__private_constructor_tag{}, date, value};
4540
}
4641

4742
#else // _LIBCPP_VERSION

libcxx/utils/generate_iwyu_mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def IWYU_mapping(header: str) -> typing.Optional[typing.List[str]]:
1111
"__debug_utils/.+",
1212
"__fwd/get[.]h",
1313
"__support/.+",
14+
"__utility/private_constructor_tag.h",
1415
]
1516
if any(re.match(pattern, header) for pattern in ignore):
1617
return None

0 commit comments

Comments
 (0)