Search code examples
c++visual-studiowarningsassertcpp-core-guidelines

Assert is seen as C style cast in Visual Studio


Here is the error and a glimpse of the code One of my courses demands me to use Warning Level 4 and to treat warnings as errors in Visual Studio. Beside that, we also need to activate Cpp Core Guidelines. However, since I activated these options I've been haunted by warning error C26493 (don't use C style casts). Apparently, they consider my "assert" tests as C style casts. I haven't seen any other student having this problem. Can somebody help me fix this thing?


Solution

  • Assert is a macro that expands (in visual studio) to:

    
        #define assert(expression) (void)(                                                       \
                (!!(expression)) ||                                                              \
                (_wassert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)), 0) \
            )
    

    As you can see, there is a C-style case to void.