Coverage Report

Created: 2025-07-18 06:50

/src/cctz/src/zone_info_source.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 Google Inc. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//   https://www.apache.org/licenses/LICENSE-2.0
8
//
9
//   Unless required by applicable law or agreed to in writing, software
10
//   distributed under the License is distributed on an "AS IS" BASIS,
11
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//   See the License for the specific language governing permissions and
13
//   limitations under the License.
14
15
#include "cctz/zone_info_source.h"
16
17
namespace cctz {
18
19
// Defined out-of-line to avoid emitting a weak vtable in all TUs.
20
145
ZoneInfoSource::~ZoneInfoSource() {}
21
0
std::string ZoneInfoSource::Version() const { return std::string(); }
22
23
}  // namespace cctz
24
25
namespace cctz_extension {
26
27
namespace {
28
29
// A default for cctz_extension::zone_info_source_factory, which simply
30
// defers to the fallback factory.
31
std::unique_ptr<cctz::ZoneInfoSource> DefaultFactory(
32
    const std::string& name,
33
    const std::function<std::unique_ptr<cctz::ZoneInfoSource>(
34
657
        const std::string& name)>& fallback_factory) {
35
657
  return fallback_factory(name);
36
657
}
37
38
}  // namespace
39
40
// A "weak" definition for cctz_extension::zone_info_source_factory.
41
// The user may override this with their own "strong" definition (see
42
// zone_info_source.h).
43
#if !defined(__has_attribute)
44
#define __has_attribute(x) 0
45
#endif
46
// MinGW is GCC on Windows, so while it asserts __has_attribute(weak), the
47
// Windows linker cannot handle that. Nor does the MinGW compiler know how to
48
// pass "#pragma comment(linker, ...)" to the Windows linker.
49
#if (__has_attribute(weak) || defined(__GNUC__)) && !defined(__MINGW32__) && !defined(__CYGWIN__)
50
ZoneInfoSourceFactory zone_info_source_factory
51
    __attribute__((weak)) = DefaultFactory;
52
#elif defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_LIBCPP_VERSION)
53
extern ZoneInfoSourceFactory zone_info_source_factory;
54
extern ZoneInfoSourceFactory default_factory;
55
ZoneInfoSourceFactory default_factory = DefaultFactory;
56
#if defined(_M_IX86) || defined(_M_ARM)
57
#pragma comment( \
58
    linker,      \
59
    "/alternatename:?zone_info_source_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZA=?default_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZA")
60
#elif defined(_M_IA_64) || defined(_M_AMD64) || defined(_M_ARM64)
61
#pragma comment( \
62
    linker,      \
63
    "/alternatename:?zone_info_source_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZEA=?default_factory@cctz_extension@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@@U?$default_delete@VZoneInfoSource@cctz@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@3@@ZEA")
64
#else
65
#error Unsupported MSVC platform
66
#endif  // _M_<PLATFORM>
67
#else
68
// Make it a "strong" definition if we have no other choice.
69
ZoneInfoSourceFactory zone_info_source_factory = DefaultFactory;
70
#endif
71
72
}  // namespace cctz_extension