簡體   English   中英

無法始終為具有 #pragma 或項目警告級別的標頭禁用 Visual Studio 2019 警告

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

我將 SDL2/GLAD 和stb_image.h與 OpenGL 一起使用,但我的問題與該事實無關。 我正在編輯所有配置下的屬性,並且我沒有使用預編譯的頭文件。

我想將警告級別提高到 /W4 甚至 /Wall。 但是, /Wall 給我最多 1273 個錯誤,大部分來自數學庫glm 所以,我將我的外部包含包裝在#pragma push/pop 指令中,但它似乎什么也沒做。 使用#pragma warning(disable : n)專門禁用警告也無濟於事。

當我開始寫這個問題時,無論我如何或在何處放置我的#pragma 指令(圍繞標題、在標題內、圍繞函數、圍繞調用),或者我是否將我的項目警告級別設置為從 /W0 到 /W4 的任何位置,大約80 個錯誤會潛入:一個來自 SDL2,其余來自stb_image.h 但是,在測試期間隨機,我的錯誤列表可以在從stb_image.h到 70+ 的 ~7 個錯誤之間跳轉。

我正在努力尋找 Visual Studio 如何處理錯誤的一致性。 我只想關閉來自外部頭文件和庫的錯誤,所以我只能看到我編寫的代碼中的錯誤。 我究竟做錯了什么?

#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 };
}

// ...

這可能是因為 IntelliSense,它似乎忽略了“#pragma warning(push, 0)”

IntelliSense 非常不穩定(我們已經到了 2022 年!)

為我解決問題的是在列表框中選擇“僅構建”,如下所示:

錯誤列表 - 僅構建

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM