6
6
7
7
// The type_caster ODR guard feature requires Translation-Unit-local entities
8
8
// (https://en.cppreference.com/w/cpp/language/tu_local), a C++20 feature, but
9
- // all tested C++17 compilers support this feature already.
9
+ // almost all tested C++17 compilers support this feature already.
10
10
#if !defined(PYBIND11_TYPE_CASTER_ODR_GUARD_ON) && !defined(PYBIND11_TYPE_CASTER_ODR_GUARD_OFF) \
11
+ && !defined(__INTEL_COMPILER) \
11
12
&& ((defined(_MSC_VER) && _MSC_VER >= 1920 ) || defined(PYBIND11_CPP17))
12
13
# define PYBIND11_TYPE_CASTER_ODR_GUARD_ON
13
14
#endif
15
+ // To explain the above:
16
+ // * MSVC 2017 does not support __builtin_FILE(), __builtin_LINE().
17
+ // * Intel 2021.6.0.20220226 (g++ 9.4 mode) __builtin_LINE() is unreliable
18
+ // (line numbers vary between translation units).
14
19
15
20
#ifndef PYBIND11_TYPE_CASTER_ODR_GUARD_ON
16
21
20
25
21
26
#else
22
27
23
- # if !defined(PYBIND11_CPP20) && defined(__GNUC__) && !defined(__clang__) \
24
- && !defined(__INTEL_COMPILER)
28
+ # if !defined(PYBIND11_CPP20) && defined(__GNUC__) && !defined(__clang__)
25
29
# pragma GCC diagnostic ignored "-Wsubobject-linkage"
26
30
# endif
27
31
@@ -82,15 +86,15 @@ inline void type_caster_odr_guard_impl(const std::type_info &intrinsic_type_info
82
86
const char *source_file_line_from_macros,
83
87
const src_loc &sloc,
84
88
bool throw_disabled) {
89
+ std::string source_file_line_from_sloc
90
+ = std::string (sloc.file ) + ' :' + std::to_string (sloc.line );
85
91
// std::cout cannot be used here: static initialization could be incomplete.
86
- # define PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_PRINTF_ON
92
+ # define PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_PRINTF_OFF
87
93
# ifdef PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_PRINTF_ON
88
94
std::fprintf (stdout,
89
95
" \n TYPE_CASTER_ODR_GUARD_IMPL %s %s\n " ,
90
96
clean_type_id (intrinsic_type_info.name ()).c_str (),
91
97
source_file_line_from_macros);
92
- std::string source_file_line_from_sloc
93
- = std::string (sloc.file ) + ' :' + std::to_string (sloc.line );
94
98
std::fprintf (stdout,
95
99
" %s %s %s\n " ,
96
100
(source_file_line_from_sloc == source_file_line_from_macros
@@ -99,6 +103,8 @@ inline void type_caster_odr_guard_impl(const std::type_info &intrinsic_type_info
99
103
clean_type_id (intrinsic_type_info.name ()).c_str (),
100
104
source_file_line_from_sloc.c_str ());
101
105
std::fflush (stdout);
106
+ # else
107
+ silence_unused_warnings (source_file_line_from_macros);
102
108
# endif
103
109
auto ins = type_caster_odr_guard_registry ().insert (
104
110
{std::type_index (intrinsic_type_info), source_file_line_from_sloc});
0 commit comments