brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · d8dd244 Raw
49 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H11#define SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H12 13// A few tests are built in C mode or in C++03 mode. The initialization14// of init_crt_anchor is a C++ feature, and <crtdbg.h> ends up including15// MSVC header code which breaks in C++03 mode. Therefore, only expand16// the body of this header when included in C++ >= 11 mode. As this file17// is included in every single translation unit, we're intentionally not18// including test_macros.h (for TEST_STD_VER) but try to keep it to the19// bare minimum.20#if defined(__cplusplus) && __cplusplus > 199711L21#ifndef _DEBUG22#error _DEBUG must be defined when using this header23#endif24 25#ifndef _WIN3226#error This header can only be used when targeting Windows27#endif28 29#include <crtdbg.h>30 31// On Windows in debug builds the default assertion handler opens a new dialog32// window which must be dismissed manually by the user. This function overrides33// that setting and instead changes the assertion handler to log to stderr34// instead.35inline int init_crt_report_mode() {36  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);37  _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);38  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);39  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);40  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);41  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);42  return 0;43}44 45static int init_crt_anchor = init_crt_report_mode();46#endif // defined(__cplusplus) && __cplusplus > 199711L47 48#endif // SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H49