0

I need to make sure the header I'm using is compiled with the /EHa compiler switch?

How can I do that?

zumalifeguard
  • 8,648
  • 5
  • 43
  • 56
  • header -> library? – user4581301 Jul 29 '17 at 04:18
  • header as in, a class that's stand alone that can be used by simply including the header, header-only, like STL. I'm making assumptions about exception handling. I want to validate those assumptions and warn the user who is including the header if they are not compiling it correctly. – zumalifeguard Jul 29 '17 at 05:30
  • Ah ha! I get you. The way I read your question you were using the header, not providing it. – user4581301 Jul 29 '17 at 06:11

1 Answers1

0
inline bool CodeHasEHaSwitch()
{
    bool dtorCalled = false;

    struct CCheckEHaSwitch
    {
        CCheckEHaSwitch( bool& dtorCalled) : dtorCalled( dtorCalled ) {}
        ~CCheckEHaSwitch() {  dtorCalled = true; }
        bool& dtorCalled;

        static void Win32ExceptionTranslator( unsigned int nExceptionCode,
        EXCEPTION_POINTERS *pExceptionInfo )
        {  throw nExceptionCode; }
    };

    _se_translator_function pfnPrevSeTranslator =
        _set_se_translator( CCheckEHaSwitch::Win32ExceptionTranslator );
    try
    {
        CCheckEHaSwitch test( dtorCalled );

        *((int*)0) = 0;  // generate access violation
    }
    catch (unsigned int)
    {
    }

    _set_se_translator( pfnPrevSeTranslator );

    return dtorCalled;
}
zumalifeguard
  • 8,648
  • 5
  • 43
  • 56