Search code examples
c++static-assert

I don't know why this static_assert() code doesn't work


This is the code:

#pragma once

#include <stdint.h>

namespace Detours
{
    static_assert(sizeof(uintptr_t) == sizeof(void *));
}

I'm getting this error message:

Error (active) E2783 expected a comma (the one-argument version of static_assert is not enabled in this mode)

Solution

  • The static_assert declaration allows the message parameter to be omitted since C++17. (cppreference)

    You need to enable C++17 in your compiler, or complete the message parameter this way:

    static_assert(sizeof(uintptr_t) == sizeof(void *), "The message you want to show.");
    

    See also

    How to enable C++17 compiling in Visual Studio?