2 //===----------------------------------------------------------------------===//
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-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
11 #define SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
13 // A few tests are built in C mode or in C++03 mode. The initialization
14 // of init_crt_anchor is a C++ feature, and <crtdbg.h> ends up including
15 // MSVC header code which breaks in C++03 mode. Therefore, only expand
16 // the body of this header when included in C++ >= 11 mode. As this file
17 // is included in every single translation unit, we're intentionally not
18 // including test_macros.h (for TEST_STD_VER) but try to keep it to the
20 #if defined(__cplusplus) && __cplusplus > 199711L
22 #error _DEBUG must be defined when using this header
26 #error This header can only be used when targeting Windows
31 // On Windows in debug builds the default assertion handler opens a new dialog
32 // window which must be dismissed manually by the user. This function overrides
33 // that setting and instead changes the assertion handler to log to stderr
35 inline 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
);
45 static int init_crt_anchor
= init_crt_report_mode();
46 #endif // defined(__cplusplus) && __cplusplus > 199711L
48 #endif // SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H