Skip to content

Silencing warnings from official headers #8859

@derek-gerstmann

Description

@derek-gerstmann

The HalideRuntime.h and HalideBuffer.h header files can cause warnings to be emitted when compiled with -pedantic which can be a problem if a project is compiled with -Werror.

These are the pragmas I needed to add around the header files to avoid any warnings or errors:

#if defined(__GNUC__) || defined(__clang__)
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-parameter"
    #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#elif defined(_MSC_VER)
    #pragma warning(push)
    #pragma warning(disable : 4100) // unused formal parameter"
    #pragma warning(disable : 4700) // uninitialized local variable
    #pragma warning(disable : 4701) // potentially uninitialized local variable
    #pragma warning(disable : 4127) // conditional expression is constant
    #pragma warning(disable : 4702) // unreachable code
#endif

#include "HalideRuntime.h"
#include "HalideBuffer.h"

#if defined(__GNUC__) || defined(__clang__)
    #pragma GCC diagnostic pop
#elif defined(_MSC_VER)
    #pragma warning(pop)
#endif

Likewise, the halide_image_io.h caused similar problems under msvc. These are the pragmas I needed to silence those warnings:

#if defined(_MSC_VER)
    #pragma warning(push)
    #pragma warning(disable : 4100) // unreferenced formal parameter
    #pragma warning(disable : 4244) // conversion from 'XXX' to 'XXX', possible loss of data
    #pragma warning(disable : 4267) // 'initializing': conversion from 'XXX' to 'XXX', possible loss of data)
    #pragma warning(disable : 4456) // declaration of 'XXX' hides previous local declaration 
    #pragma warning(disable : 4458) // declaration of 'XXX' hides class member
    #pragma warning(disable : 4459) // declaration of 'XXX' hides global declaration
    #pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
    #pragma warning(disable : 4996) // function or variable may be unsafe. 
#endif

#include "halide_image_io.h"

#if defined(_MSC_VER)
    #pragma warning(pop)
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    code_cleanupNo functional changes. Reformatting, reorganizing, or refactoring existing code.usability

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions