5

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)
cigien
  • 57,834
  • 11
  • 73
  • 112
terran20000
  • 61
  • 1
  • 3
  • Do you have some reason to think it should work? – cigien Nov 29 '20 at 01:35
  • 2
    Define "doesn't work". What outcome do you expect, and what do you observe instead? – Igor Tandetnik Nov 29 '20 at 01:37
  • It should work because i'm watching guy from youtube and his code does work but my code isn't working is it maybe because it is 1 year old? – terran20000 Nov 29 '20 at 01:39
  • That's not a technical reason for why you think the code should work. What makes you think the youtube video is correct? – cigien Nov 29 '20 at 01:41
  • 2
    Error (active) E2783 expected a comma (the one-argument version of static_assert is not enabled in this mode) that is a error that i got – terran20000 Nov 29 '20 at 01:42
  • You need to compile the code in c++17 mode. And add that information to the question. – cigien Nov 29 '20 at 01:44
  • 4
    `static_assert` requires a second parameter - the error message - before C++17. Apparently, C++17 is not enabled in your compiler. Either figure out how to enable it, or add the error message, as in `static_assert(condition, "Error message here")` – Igor Tandetnik Nov 29 '20 at 01:44
  • 2
    You probably want to add an error message anyways. – drescherjm Nov 29 '20 at 01:48
  • do you have youtube video or site where i can do that for vs 2019 – terran20000 Nov 29 '20 at 01:48
  • 2
    Enabling `c++17` is in the project settings. Properties -> C/C++ ->Language-> "C++ Language Standard" – drescherjm Nov 29 '20 at 01:48

2 Answers2

13

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?

Sprite
  • 3,222
  • 1
  • 12
  • 29
8

The language feature known (by Microsoft, at least) as "terse static assert" - that is, a static_assert() with only one argument - was introduced in the C++17 Standard. Before that, the second argument (a string literal, the error message) is required. So, compiling your code with (for example) MSVC and the "/std:C++14" flag, gives this error:

error C2429: language feature 'terse static assert' requires compiler flag '/std:c++17'

And clang-cl gives:

warning : static_assert with no message is a C++17 extension [-Wc++17-extensions]

To fix this, either switch your compiler to conform to the C++17 Standard or, if you don't have that possibility, add the required second argument:

    static_assert(sizeof(uintptr_t) == sizeof(void*), "Wrong uintptr_t size!");

But note, even with that, there is no guarantee that the assertion will succeed! The uintptr_t type is required only to be of sufficient size to correctly accommodate a pointer; it does not have to be the exact same size. See: What is uintptr_t data type.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83