printf.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. // Formatting library for C++ - legacy printf implementation
  3. //
  4. // Copyright (c) 2012 - 2016, Victor Zverovich
  5. // All rights reserved.
  6. //
  7. // For the license information refer to format.h.
  8. #ifndef FMT_PRINTF_H_
  9. #define FMT_PRINTF_H_
  10. #ifndef FMT_MODULE
  11. # include <algorithm> // std::find
  12. # include <limits> // std::numeric_limits
  13. #endif
  14. #include "format.h"
  15. FMT_BEGIN_NAMESPACE
  16. FMT_BEGIN_EXPORT
  17. template <typename Char> class basic_printf_context {
  18. private:
  19. basic_appender<Char> out_;
  20. basic_format_args<basic_printf_context> args_;
  21. static_assert(std::is_same<Char, char>::value ||
  22. std::is_same<Char, wchar_t>::value,
  23. "Unsupported code unit type.");
  24. public:
  25. using char_type = Char;
  26. enum { builtin_types = 1 };
  27. /// Constructs a `printf_context` object. References to the arguments are
  28. /// stored in the context object so make sure they have appropriate lifetimes.
  29. basic_printf_context(basic_appender<Char> out,
  30. basic_format_args<basic_printf_context> args)
  31. : out_(out), args_(args) {}
  32. auto out() -> basic_appender<Char> { return out_; }
  33. void advance_to(basic_appender<Char>) {}
  34. auto locale() -> locale_ref { return {}; }
  35. auto arg(int id) const -> basic_format_arg<basic_printf_context> {
  36. return args_.get(id);
  37. }
  38. };
  39. namespace detail {
  40. // Return the result via the out param to workaround gcc bug 77539.
  41. template <bool IS_CONSTEXPR, typename T, typename Ptr = const T*>
  42. FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr& out) -> bool {
  43. for (out = first; out != last; ++out) {
  44. if (*out == value) return true;
  45. }
  46. return false;
  47. }
  48. template <>
  49. inline auto find<false, char>(const char* first, const char* last, char value,
  50. const char*& out) -> bool {
  51. out =
  52. static_cast<const char*>(memchr(first, value, to_unsigned(last - first)));
  53. return out != nullptr;
  54. }
  55. // Checks if a value fits in int - used to avoid warnings about comparing
  56. // signed and unsigned integers.
  57. template <bool IS_SIGNED> struct int_checker {
  58. template <typename T> static auto fits_in_int(T value) -> bool {
  59. return value <= to_unsigned(max_value<int>());
  60. }
  61. inline static auto fits_in_int(bool) -> bool { return true; }
  62. };
  63. template <> struct int_checker<true> {
  64. template <typename T> static auto fits_in_int(T value) -> bool {
  65. return value >= (std::numeric_limits<int>::min)() &&
  66. value <= max_value<int>();
  67. }
  68. inline static auto fits_in_int(int) -> bool { return true; }
  69. };
  70. struct printf_precision_handler {
  71. template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
  72. auto operator()(T value) -> int {
  73. if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
  74. report_error("number is too big");
  75. return max_of(static_cast<int>(value), 0);
  76. }
  77. template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
  78. auto operator()(T) -> int {
  79. report_error("precision is not integer");
  80. return 0;
  81. }
  82. };
  83. // An argument visitor that returns true iff arg is a zero integer.
  84. struct is_zero_int {
  85. template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
  86. auto operator()(T value) -> bool {
  87. return value == 0;
  88. }
  89. template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
  90. auto operator()(T) -> bool {
  91. return false;
  92. }
  93. };
  94. template <typename T> struct make_unsigned_or_bool : std::make_unsigned<T> {};
  95. template <> struct make_unsigned_or_bool<bool> {
  96. using type = bool;
  97. };
  98. template <typename T, typename Context> class arg_converter {
  99. private:
  100. using char_type = typename Context::char_type;
  101. basic_format_arg<Context>& arg_;
  102. char_type type_;
  103. public:
  104. arg_converter(basic_format_arg<Context>& arg, char_type type)
  105. : arg_(arg), type_(type) {}
  106. void operator()(bool value) {
  107. if (type_ != 's') operator()<bool>(value);
  108. }
  109. template <typename U, FMT_ENABLE_IF(std::is_integral<U>::value)>
  110. void operator()(U value) {
  111. bool is_signed = type_ == 'd' || type_ == 'i';
  112. using target_type = conditional_t<std::is_same<T, void>::value, U, T>;
  113. if (const_check(sizeof(target_type) <= sizeof(int))) {
  114. // Extra casts are used to silence warnings.
  115. using unsigned_type = typename make_unsigned_or_bool<target_type>::type;
  116. if (is_signed)
  117. arg_ = static_cast<int>(static_cast<target_type>(value));
  118. else
  119. arg_ = static_cast<unsigned>(static_cast<unsigned_type>(value));
  120. } else {
  121. // glibc's printf doesn't sign extend arguments of smaller types:
  122. // std::printf("%lld", -42); // prints "4294967254"
  123. // but we don't have to do the same because it's a UB.
  124. if (is_signed)
  125. arg_ = static_cast<long long>(value);
  126. else
  127. arg_ = static_cast<typename make_unsigned_or_bool<U>::type>(value);
  128. }
  129. }
  130. template <typename U, FMT_ENABLE_IF(!std::is_integral<U>::value)>
  131. void operator()(U) {} // No conversion needed for non-integral types.
  132. };
  133. // Converts an integer argument to T for printf, if T is an integral type.
  134. // If T is void, the argument is converted to corresponding signed or unsigned
  135. // type depending on the type specifier: 'd' and 'i' - signed, other -
  136. // unsigned).
  137. template <typename T, typename Context, typename Char>
  138. void convert_arg(basic_format_arg<Context>& arg, Char type) {
  139. arg.visit(arg_converter<T, Context>(arg, type));
  140. }
  141. // Converts an integer argument to char for printf.
  142. template <typename Context> class char_converter {
  143. private:
  144. basic_format_arg<Context>& arg_;
  145. public:
  146. explicit char_converter(basic_format_arg<Context>& arg) : arg_(arg) {}
  147. template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
  148. void operator()(T value) {
  149. arg_ = static_cast<typename Context::char_type>(value);
  150. }
  151. template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
  152. void operator()(T) {} // No conversion needed for non-integral types.
  153. };
  154. // An argument visitor that return a pointer to a C string if argument is a
  155. // string or null otherwise.
  156. template <typename Char> struct get_cstring {
  157. template <typename T> auto operator()(T) -> const Char* { return nullptr; }
  158. auto operator()(const Char* s) -> const Char* { return s; }
  159. };
  160. // Checks if an argument is a valid printf width specifier and sets
  161. // left alignment if it is negative.
  162. class printf_width_handler {
  163. private:
  164. format_specs& specs_;
  165. public:
  166. inline explicit printf_width_handler(format_specs& specs) : specs_(specs) {}
  167. template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
  168. auto operator()(T value) -> unsigned {
  169. auto width = static_cast<uint32_or_64_or_128_t<T>>(value);
  170. if (detail::is_negative(value)) {
  171. specs_.set_align(align::left);
  172. width = 0 - width;
  173. }
  174. unsigned int_max = to_unsigned(max_value<int>());
  175. if (width > int_max) report_error("number is too big");
  176. return static_cast<unsigned>(width);
  177. }
  178. template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
  179. auto operator()(T) -> unsigned {
  180. report_error("width is not integer");
  181. return 0;
  182. }
  183. };
  184. // Workaround for a bug with the XL compiler when initializing
  185. // printf_arg_formatter's base class.
  186. template <typename Char>
  187. auto make_arg_formatter(basic_appender<Char> iter, format_specs& s)
  188. -> arg_formatter<Char> {
  189. return {iter, s, locale_ref()};
  190. }
  191. // The `printf` argument formatter.
  192. template <typename Char>
  193. class printf_arg_formatter : public arg_formatter<Char> {
  194. private:
  195. using base = arg_formatter<Char>;
  196. using context_type = basic_printf_context<Char>;
  197. context_type& context_;
  198. void write_null_pointer(bool is_string = false) {
  199. auto s = this->specs;
  200. s.set_type(presentation_type::none);
  201. write_bytes<Char>(this->out, is_string ? "(null)" : "(nil)", s);
  202. }
  203. template <typename T> void write(T value) {
  204. detail::write<Char>(this->out, value, this->specs, this->locale);
  205. }
  206. public:
  207. printf_arg_formatter(basic_appender<Char> iter, format_specs& s,
  208. context_type& ctx)
  209. : base(make_arg_formatter(iter, s)), context_(ctx) {}
  210. void operator()(monostate value) { write(value); }
  211. template <typename T, FMT_ENABLE_IF(detail::is_integral<T>::value)>
  212. void operator()(T value) {
  213. // MSVC2013 fails to compile separate overloads for bool and Char so use
  214. // std::is_same instead.
  215. if (!std::is_same<T, Char>::value) {
  216. write(value);
  217. return;
  218. }
  219. format_specs s = this->specs;
  220. if (s.type() != presentation_type::none &&
  221. s.type() != presentation_type::chr) {
  222. return (*this)(static_cast<int>(value));
  223. }
  224. s.set_sign(sign::none);
  225. s.clear_alt();
  226. s.set_fill(' '); // Ignore '0' flag for char types.
  227. // align::numeric needs to be overwritten here since the '0' flag is
  228. // ignored for non-numeric types
  229. if (s.align() == align::none || s.align() == align::numeric)
  230. s.set_align(align::right);
  231. detail::write<Char>(this->out, static_cast<Char>(value), s);
  232. }
  233. template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
  234. void operator()(T value) {
  235. write(value);
  236. }
  237. void operator()(const char* value) {
  238. if (value)
  239. write(value);
  240. else
  241. write_null_pointer(this->specs.type() != presentation_type::pointer);
  242. }
  243. void operator()(const wchar_t* value) {
  244. if (value)
  245. write(value);
  246. else
  247. write_null_pointer(this->specs.type() != presentation_type::pointer);
  248. }
  249. void operator()(basic_string_view<Char> value) { write(value); }
  250. void operator()(const void* value) {
  251. if (value)
  252. write(value);
  253. else
  254. write_null_pointer();
  255. }
  256. void operator()(typename basic_format_arg<context_type>::handle handle) {
  257. auto parse_ctx = parse_context<Char>({});
  258. handle.format(parse_ctx, context_);
  259. }
  260. };
  261. template <typename Char>
  262. void parse_flags(format_specs& specs, const Char*& it, const Char* end) {
  263. for (; it != end; ++it) {
  264. switch (*it) {
  265. case '-': specs.set_align(align::left); break;
  266. case '+': specs.set_sign(sign::plus); break;
  267. case '0': specs.set_fill('0'); break;
  268. case ' ':
  269. if (specs.sign() != sign::plus) specs.set_sign(sign::space);
  270. break;
  271. case '#': specs.set_alt(); break;
  272. default: return;
  273. }
  274. }
  275. }
  276. template <typename Char, typename GetArg>
  277. auto parse_header(const Char*& it, const Char* end, format_specs& specs,
  278. GetArg get_arg) -> int {
  279. int arg_index = -1;
  280. Char c = *it;
  281. if (c >= '0' && c <= '9') {
  282. // Parse an argument index (if followed by '$') or a width possibly
  283. // preceded with '0' flag(s).
  284. int value = parse_nonnegative_int(it, end, -1);
  285. if (it != end && *it == '$') { // value is an argument index
  286. ++it;
  287. arg_index = value != -1 ? value : max_value<int>();
  288. } else {
  289. if (c == '0') specs.set_fill('0');
  290. if (value != 0) {
  291. // Nonzero value means that we parsed width and don't need to
  292. // parse it or flags again, so return now.
  293. if (value == -1) report_error("number is too big");
  294. specs.width = value;
  295. return arg_index;
  296. }
  297. }
  298. }
  299. parse_flags(specs, it, end);
  300. // Parse width.
  301. if (it != end) {
  302. if (*it >= '0' && *it <= '9') {
  303. specs.width = parse_nonnegative_int(it, end, -1);
  304. if (specs.width == -1) report_error("number is too big");
  305. } else if (*it == '*') {
  306. ++it;
  307. specs.width = static_cast<int>(
  308. get_arg(-1).visit(detail::printf_width_handler(specs)));
  309. }
  310. }
  311. return arg_index;
  312. }
  313. inline auto parse_printf_presentation_type(char c, type t, bool& upper)
  314. -> presentation_type {
  315. using pt = presentation_type;
  316. constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
  317. switch (c) {
  318. case 'd': return in(t, integral_set) ? pt::dec : pt::none;
  319. case 'o': return in(t, integral_set) ? pt::oct : pt::none;
  320. case 'X': upper = true; FMT_FALLTHROUGH;
  321. case 'x': return in(t, integral_set) ? pt::hex : pt::none;
  322. case 'E': upper = true; FMT_FALLTHROUGH;
  323. case 'e': return in(t, float_set) ? pt::exp : pt::none;
  324. case 'F': upper = true; FMT_FALLTHROUGH;
  325. case 'f': return in(t, float_set) ? pt::fixed : pt::none;
  326. case 'G': upper = true; FMT_FALLTHROUGH;
  327. case 'g': return in(t, float_set) ? pt::general : pt::none;
  328. case 'A': upper = true; FMT_FALLTHROUGH;
  329. case 'a': return in(t, float_set) ? pt::hexfloat : pt::none;
  330. case 'c': return in(t, integral_set) ? pt::chr : pt::none;
  331. case 's': return in(t, string_set | cstring_set) ? pt::string : pt::none;
  332. case 'p': return in(t, pointer_set | cstring_set) ? pt::pointer : pt::none;
  333. default: return pt::none;
  334. }
  335. }
  336. template <typename Char, typename Context>
  337. void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
  338. basic_format_args<Context> args) {
  339. using iterator = basic_appender<Char>;
  340. auto out = iterator(buf);
  341. auto context = basic_printf_context<Char>(out, args);
  342. auto parse_ctx = parse_context<Char>(format);
  343. // Returns the argument with specified index or, if arg_index is -1, the next
  344. // argument.
  345. auto get_arg = [&](int arg_index) {
  346. if (arg_index < 0)
  347. arg_index = parse_ctx.next_arg_id();
  348. else
  349. parse_ctx.check_arg_id(--arg_index);
  350. auto arg = context.arg(arg_index);
  351. if (!arg) report_error("argument not found");
  352. return arg;
  353. };
  354. const Char* start = parse_ctx.begin();
  355. const Char* end = parse_ctx.end();
  356. auto it = start;
  357. while (it != end) {
  358. if (!find<false, Char>(it, end, '%', it)) {
  359. it = end; // find leaves it == nullptr if it doesn't find '%'.
  360. break;
  361. }
  362. Char c = *it++;
  363. if (it != end && *it == c) {
  364. write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
  365. start = ++it;
  366. continue;
  367. }
  368. write(out, basic_string_view<Char>(start, to_unsigned(it - 1 - start)));
  369. auto specs = format_specs();
  370. specs.set_align(align::right);
  371. // Parse argument index, flags and width.
  372. int arg_index = parse_header(it, end, specs, get_arg);
  373. if (arg_index == 0) report_error("argument not found");
  374. // Parse precision.
  375. if (it != end && *it == '.') {
  376. ++it;
  377. c = it != end ? *it : 0;
  378. if ('0' <= c && c <= '9') {
  379. specs.precision = parse_nonnegative_int(it, end, 0);
  380. } else if (c == '*') {
  381. ++it;
  382. specs.precision =
  383. static_cast<int>(get_arg(-1).visit(printf_precision_handler()));
  384. } else {
  385. specs.precision = 0;
  386. }
  387. }
  388. auto arg = get_arg(arg_index);
  389. // For d, i, o, u, x, and X conversion specifiers, if a precision is
  390. // specified, the '0' flag is ignored
  391. if (specs.precision >= 0 && is_integral_type(arg.type())) {
  392. // Ignore '0' for non-numeric types or if '-' present.
  393. specs.set_fill(' ');
  394. }
  395. if (specs.precision >= 0 && arg.type() == type::cstring_type) {
  396. auto str = arg.visit(get_cstring<Char>());
  397. auto str_end = str + specs.precision;
  398. auto nul = std::find(str, str_end, Char());
  399. auto sv = basic_string_view<Char>(
  400. str, to_unsigned(nul != str_end ? nul - str : specs.precision));
  401. arg = sv;
  402. }
  403. if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt();
  404. if (specs.fill_unit<Char>() == '0') {
  405. if (is_arithmetic_type(arg.type()) && specs.align() != align::left) {
  406. specs.set_align(align::numeric);
  407. } else {
  408. // Ignore '0' flag for non-numeric types or if '-' flag is also present.
  409. specs.set_fill(' ');
  410. }
  411. }
  412. // Parse length and convert the argument to the required type.
  413. c = it != end ? *it++ : 0;
  414. Char t = it != end ? *it : 0;
  415. switch (c) {
  416. case 'h':
  417. if (t == 'h') {
  418. ++it;
  419. t = it != end ? *it : 0;
  420. convert_arg<signed char>(arg, t);
  421. } else {
  422. convert_arg<short>(arg, t);
  423. }
  424. break;
  425. case 'l':
  426. if (t == 'l') {
  427. ++it;
  428. t = it != end ? *it : 0;
  429. convert_arg<long long>(arg, t);
  430. } else {
  431. convert_arg<long>(arg, t);
  432. }
  433. break;
  434. case 'j': convert_arg<intmax_t>(arg, t); break;
  435. case 'z': convert_arg<size_t>(arg, t); break;
  436. case 't': convert_arg<std::ptrdiff_t>(arg, t); break;
  437. case 'L':
  438. // printf produces garbage when 'L' is omitted for long double, no
  439. // need to do the same.
  440. break;
  441. default: --it; convert_arg<void>(arg, c);
  442. }
  443. // Parse type.
  444. if (it == end) report_error("invalid format string");
  445. char type = static_cast<char>(*it++);
  446. if (is_integral_type(arg.type())) {
  447. // Normalize type.
  448. switch (type) {
  449. case 'i':
  450. case 'u': type = 'd'; break;
  451. case 'c':
  452. arg.visit(char_converter<basic_printf_context<Char>>(arg));
  453. break;
  454. }
  455. }
  456. bool upper = false;
  457. specs.set_type(parse_printf_presentation_type(type, arg.type(), upper));
  458. if (specs.type() == presentation_type::none)
  459. report_error("invalid format specifier");
  460. if (upper) specs.set_upper();
  461. start = it;
  462. // Format argument.
  463. arg.visit(printf_arg_formatter<Char>(out, specs, context));
  464. }
  465. write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
  466. }
  467. } // namespace detail
  468. using printf_context = basic_printf_context<char>;
  469. using wprintf_context = basic_printf_context<wchar_t>;
  470. using printf_args = basic_format_args<printf_context>;
  471. using wprintf_args = basic_format_args<wprintf_context>;
  472. /// Constructs an `format_arg_store` object that contains references to
  473. /// arguments and can be implicitly converted to `printf_args`.
  474. template <typename Char = char, typename... T>
  475. inline auto make_printf_args(T&... args)
  476. -> decltype(fmt::make_format_args<basic_printf_context<Char>>(args...)) {
  477. return fmt::make_format_args<basic_printf_context<Char>>(args...);
  478. }
  479. template <typename Char> struct vprintf_args {
  480. using type = basic_format_args<basic_printf_context<Char>>;
  481. };
  482. template <typename Char>
  483. inline auto vsprintf(basic_string_view<Char> fmt,
  484. typename vprintf_args<Char>::type args)
  485. -> std::basic_string<Char> {
  486. auto buf = basic_memory_buffer<Char>();
  487. detail::vprintf(buf, fmt, args);
  488. return {buf.data(), buf.size()};
  489. }
  490. /**
  491. * Formats `args` according to specifications in `fmt` and returns the result
  492. * as as string.
  493. *
  494. * **Example**:
  495. *
  496. * std::string message = fmt::sprintf("The answer is %d", 42);
  497. */
  498. template <typename... T>
  499. inline auto sprintf(string_view fmt, const T&... args) -> std::string {
  500. return vsprintf(fmt, make_printf_args(args...));
  501. }
  502. template <typename... T>
  503. FMT_DEPRECATED auto sprintf(basic_string_view<wchar_t> fmt, const T&... args)
  504. -> std::wstring {
  505. return vsprintf(fmt, make_printf_args<wchar_t>(args...));
  506. }
  507. template <typename Char>
  508. auto vfprintf(std::FILE* f, basic_string_view<Char> fmt,
  509. typename vprintf_args<Char>::type args) -> int {
  510. auto buf = basic_memory_buffer<Char>();
  511. detail::vprintf(buf, fmt, args);
  512. size_t size = buf.size();
  513. return std::fwrite(buf.data(), sizeof(Char), size, f) < size
  514. ? -1
  515. : static_cast<int>(size);
  516. }
  517. /**
  518. * Formats `args` according to specifications in `fmt` and writes the output
  519. * to `f`.
  520. *
  521. * **Example**:
  522. *
  523. * fmt::fprintf(stderr, "Don't %s!", "panic");
  524. */
  525. template <typename... T>
  526. inline auto fprintf(std::FILE* f, string_view fmt, const T&... args) -> int {
  527. return vfprintf(f, fmt, make_printf_args(args...));
  528. }
  529. template <typename... T>
  530. FMT_DEPRECATED auto fprintf(std::FILE* f, basic_string_view<wchar_t> fmt,
  531. const T&... args) -> int {
  532. return vfprintf(f, fmt, make_printf_args<wchar_t>(args...));
  533. }
  534. /**
  535. * Formats `args` according to specifications in `fmt` and writes the output
  536. * to `stdout`.
  537. *
  538. * **Example**:
  539. *
  540. * fmt::printf("Elapsed time: %.2f seconds", 1.23);
  541. */
  542. template <typename... T>
  543. inline auto printf(string_view fmt, const T&... args) -> int {
  544. return vfprintf(stdout, fmt, make_printf_args(args...));
  545. }
  546. FMT_END_EXPORT
  547. FMT_END_NAMESPACE
  548. #endif // FMT_PRINTF_H_
  549. #else
  550. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  551. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)