Home | History | Annotate | Download | only in support
      1 // -*- C++ -*-
      2 //===----------------------------------------------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 #ifndef SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
     11 #define SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
     12 
     13 #ifndef _DEBUG
     14 #error _DEBUG must be defined when using this header
     15 #endif
     16 
     17 #ifndef _WIN32
     18 #error This header can only be used when targeting Windows
     19 #endif
     20 
     21 #include <crtdbg.h>
     22 
     23 // On Windows in debug builds the default assertion handler opens a new dialog
     24 // window which must be dismissed manually by the user. This function overrides
     25 // that setting and instead changes the assertion handler to log to stderr
     26 // instead.
     27 inline int init_crt_report_mode() {
     28   _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
     29   _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
     30   _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
     31   return 0;
     32 }
     33 
     34 static int init_crt_anchor = init_crt_report_mode();
     35 
     36 #endif // SUPPORT_SET_WINDOWS_CRT_REPORT_MODE_H
     37