c++visual-studio-2022glm-math

Visual Studio 2022, disable warnings from glm in C++


I'm writing a program using Vulkan and GLM in C++ on the Visual Studio 2022 IDE.

GLM produces 109 warnings. Each one looks like this:

Warning C26495  Variable 'glm::tvec4<unsigned char,0>::<unnamed-tag>::<unnamed-tag>::t' is uninitialized. Always initialize a member variable (type.6). 

I'm not interested in solving these warnings because I don't want to change glm or other external dependencies. For reasons of clarity, however, I do not want to display these in the list of warnings. All other warnings should be displayed.


Solution

  • If the warning comes from a header, you can maybe do

    #pragma warning( push ) 
    #pragma warning( disable : 26495 ) 
    #include "header" 
    #pragma warning( pop )
    

    This will save (push) the current warning settings, then disable the specific error (26495). After including the header file, it will then reset the warnings back to what they were before (pop) from when they were saved. Effectively, this disabled the warning throughout the header file.

    You can also do this around blocks of code, not just includes.

    If it's from a specific line of your code, you can do

    #pragma warning( suppress : 26495 )
    

    suppress is a way to disable a warning for only the next line of code.

    If the header file you're including is in another separate folder, you can disable all warnings for files in a folder. I can't remember how to do this off the top of my head, but I've done it before for Qt files.