Skip to content

Commit 9ba32bd

Browse files
committed
Disable type_caster ODR guard for __INTEL_COMPILER (see comment). Also turn off printf.
1 parent 37e583b commit 9ba32bd

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

include/pybind11/detail/type_caster_odr_guard.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
// The type_caster ODR guard feature requires Translation-Unit-local entities
88
// (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.
1010
#if !defined(PYBIND11_TYPE_CASTER_ODR_GUARD_ON) && !defined(PYBIND11_TYPE_CASTER_ODR_GUARD_OFF) \
11+
&& !defined(__INTEL_COMPILER) \
1112
&& ((defined(_MSC_VER) && _MSC_VER >= 1920) || defined(PYBIND11_CPP17))
1213
# define PYBIND11_TYPE_CASTER_ODR_GUARD_ON
1314
#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).
1419

1520
#ifndef PYBIND11_TYPE_CASTER_ODR_GUARD_ON
1621

@@ -20,8 +25,7 @@
2025

2126
#else
2227

23-
# if !defined(PYBIND11_CPP20) && defined(__GNUC__) && !defined(__clang__) \
24-
&& !defined(__INTEL_COMPILER)
28+
# if !defined(PYBIND11_CPP20) && defined(__GNUC__) && !defined(__clang__)
2529
# pragma GCC diagnostic ignored "-Wsubobject-linkage"
2630
# endif
2731

@@ -82,15 +86,15 @@ inline void type_caster_odr_guard_impl(const std::type_info &intrinsic_type_info
8286
const char *source_file_line_from_macros,
8387
const src_loc &sloc,
8488
bool throw_disabled) {
89+
std::string source_file_line_from_sloc
90+
= std::string(sloc.file) + ':' + std::to_string(sloc.line);
8591
// 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
8793
# ifdef PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_PRINTF_ON
8894
std::fprintf(stdout,
8995
"\nTYPE_CASTER_ODR_GUARD_IMPL %s %s\n",
9096
clean_type_id(intrinsic_type_info.name()).c_str(),
9197
source_file_line_from_macros);
92-
std::string source_file_line_from_sloc
93-
= std::string(sloc.file) + ':' + std::to_string(sloc.line);
9498
std::fprintf(stdout,
9599
"%s %s %s\n",
96100
(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
99103
clean_type_id(intrinsic_type_info.name()).c_str(),
100104
source_file_line_from_sloc.c_str());
101105
std::fflush(stdout);
106+
# else
107+
silence_unused_warnings(source_file_line_from_macros);
102108
# endif
103109
auto ins = type_caster_odr_guard_registry().insert(
104110
{std::type_index(intrinsic_type_info), source_file_line_from_sloc});

0 commit comments

Comments
 (0)