简体   繁体   English

无法始终为具有 #pragma 或项目警告级别的标头禁用 Visual Studio 2019 警告

[英]Cannot consistently disable Visual Studio 2019 warnings for headers with #pragma or project warning level

I am using SDL2/GLAD and stb_image.h with OpenGL, but AFAIK my problem is independent of that fact.我将 SDL2/GLAD 和stb_image.h与 OpenGL 一起使用,但我的问题与该事实无关。 I am editing properties under all configuration and I am not using precompiled headers.我正在编辑所有配置下的属性,并且我没有使用预编译的头文件。

I want to up my warning level to /W4 or even /Wall.我想将警告级别提高到 /W4 甚至 /Wall。 However, /Wall gives me up to 1273 errors, most from the math library glm .但是, /Wall 给我最多 1273 个错误,大部分来自数学库glm So, I wrapped my external includes in a #pragma push/pop directive, but it seems to do absolutely nothing.所以,我将我的外部包含包装在#pragma push/pop 指令中,但它似乎什么也没做。 Specifically disabling warnings with #pragma warning(disable : n) does nothing either.使用#pragma warning(disable : n)专门禁用警告也无济于事。

When I started writing this question, no matter how or where I placed my #pragma directives (around headers, within headers, around functions, around calls), or whether I had my project warning level set anywhere from /W0 to /W4, about 80 errors would sneak through: one from SDL2, and the rest from stb_image.h .当我开始写这个问题时,无论我如何或在何处放置我的#pragma 指令(围绕标题、在标题内、围绕函数、围绕调用),或者我是否将我的项目警告级别设置为从 /W0 到 /W4 的任何位置,大约80 个错误会潜入:一个来自 SDL2,其余来自stb_image.h However, randomly during testing, my error list can jump between ~7 errors from stb_image.h back up to 70+.但是,在测试期间随机,我的错误列表可以在从stb_image.h到 70+ 的 ~7 个错误之间跳转。

I'm struggling to find any consistency in how Visual Studio handles errors.我正在努力寻找 Visual Studio 如何处理错误的一致性。 I just want to turn off errors from external headers and libraries so I can only see errors from code I have written.我只想关闭来自外部头文件和库的错误,所以我只能看到我编写的代码中的错误。 What am I doing wrong?我究竟做错了什么?

#pragma warning(push, 0)
#include <glad/glad.h>
#include <SDL.h>

#define STB_IMAGE_IMPLEMENTATION
#include <stb_image/stb_image.h>

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#pragma warning(pop)

#include <iostream>
#include <vector>
#include <fstream>

// ...

Image LoadTexture(const std::string& path, GLenum format) {
    int width, height, channels;
    unsigned char* data = stbi_load(path.c_str(), &width, &height, &channels, STBI_default);

    GLuint texture;
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    if (data) {
        glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
        glGenerateMipmap(GL_TEXTURE_2D);
    }
    else {
        std::cerr << "Failed to load texture " << path << std::endl;
        texture = -1; // error
    }

    stbi_image_free(data);
    return { texture, width, height, channels };
}

// ...

This is probably because of IntelliSense, it seems to ignore "#pragma warning(push, 0)"这可能是因为 IntelliSense,它似乎忽略了“#pragma warning(push, 0)”

IntelliSense is very unstable (and we are in year 2022 already!) IntelliSense 非常不稳定(我们已经到了 2022 年!)

What solved the problem for me is to select "Build Only" in the listbox, as the print bellow:为我解决问题的是在列表框中选择“仅构建”,如下所示:

错误列表 - 仅构建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 构建与智能感知警告。 有什么区别,为什么 pragma warning(disable) 不删除 intellisense 警告? - Visual Studio build vs intellisense warnings. What is the difference, and why does pragma warning(disable) not remove intellisense warning? pragma警告(禁用:4700)在Visual Studio Express 2013中不起作用 - pragma warning( disable : 4700 ) not working in Visual Studio Express 2013 有没有办法为整个解决方案设置visual studio的pragma禁用警告? - Is there a way to set a pragma disable warning for visual studio for an entire solution? 编译指示警告(推,0)不会禁用/墙警告? - pragma warning(push, 0) doesn't disable /Wall warnings? 如何在Visual Studio 2019中全局禁用C / C ++编译器的弃用警告? - How to disable deprecation warnings for C/C++ compiler globally in Visual Studio 2019? 编译 ARM64 C++ 时禁用警告? 视觉工作室 2019 - Disable Warnings when compiling ARM64 C++? Visual Studio 2019 Visual Studio 2019 标准库生成警告 - Visual Studio 2019 standard library generates warnings Visual Studio 社区 2019 无法将 cpp 文件添加到项目 - Visual Studio community 2019 cannot add cpp files to project 有没有办法用编译指示禁用所有警告? - Is there a way to disable all warnings with a pragma? 如何在 Visual Studio 2019 中禁用 C++ 的特定警告? - How do you disable a specific warning for C++ in Visual Studio 2019?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM