Warning.h#

Fully qualified name: carb/Warning.h

File members: carb/Warning.h

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.

#pragma once

#include "Compiler.h"

// MSC-specific warning macros are defined only for MSC
// CARB_IGNOREWARNING_MSC_PUSH: MSVC only; pushes the warning state
// CARB_IGNOREWARNING_MSC_POP: MSVC only; pops the warning state
// CARB_IGNOREWARNING_MSC(w): MSVC only; disables the given warning number (ex: CARB_IGNOREWARNING_MSC(4505))
// CARB_IGNOREWARNING_MSC_WITH_PUSH(w): MSVC only; combines CARB_IGNOREWARNING_MSC_PUSH and CARB_IGNOREWARNING_MSC()
#if !defined(DOXYGEN_BUILD) && CARB_COMPILER_MSC
#    define CARB_IGNOREWARNING_MSC_PUSH __pragma(warning(push))
#    define CARB_IGNOREWARNING_MSC_POP __pragma(warning(pop))
#    define CARB_IGNOREWARNING_MSC(w) __pragma(warning(disable : w))
#    define CARB_IGNOREWARNING_MSC_WITH_PUSH(w)                                                                        \
        CARB_IGNOREWARNING_MSC_PUSH                                                                                    \
        CARB_IGNOREWARNING_MSC(w)
#else
#    define CARB_IGNOREWARNING_MSC_PUSH
#    define CARB_IGNOREWARNING_MSC_POP
#    define CARB_IGNOREWARNING_MSC(w)
#    define CARB_IGNOREWARNING_MSC_WITH_PUSH(w)
#endif

// GNUC-specific helper macros are defined for GCC and Clang-infrastructure
// CARB_IGNOREWARNING_GNUC_PUSH: GCC only; pushes the warning state
// CARB_IGNOREWARNING_GNUC_POP: GCC only; pops the warning state
// CARB_IGNOREWARNING_CLANG_PUSH: Clang only; pushes the warning state
// CARB_IGNOREWARNING_CLANG_POP: Clang only; pops the warning state
// CARB_IGNOREWARNING_GNUC(w): GCC only; disables the given warning (ex: CARB_IGNOREWARNING_GNUC("-Wattributes"))
// CARB_IGNOREWARNING_GNUC_WITH_PUSH(w): GCC only; combines CARB_IGNOREWARNING_GNUC_PUSH and CARB_IGNOREWARNING_GNUC()
// CARB_IGNOREWARNING_CLANG(w): Clang only; disables the given warning (ex: CARB_IGNOREWARNING_CLANG("-Wattributes"))
// CARB_IGNOREWARNING_CLANG_WITH_PUSH(w): Clang only; combines CARB_IGNOREWARNING_CLANG_PUSH and
// CARB_IGNOREWARNING_CLANG()
#if !defined(DOXYGEN_BUILD) && (CARB_COMPILER_GNUC || CARB_TOOLCHAIN_CLANG)
#    define CARB_IGNOREWARNING_GNUC_PUSH _Pragma("GCC diagnostic push")
#    define CARB_IGNOREWARNING_GNUC_POP _Pragma("GCC diagnostic pop")
#    define INTERNAL_CARB_IGNOREWARNING_GNUC(str) _Pragma(#    str)
#    define CARB_IGNOREWARNING_GNUC(w) INTERNAL_CARB_IGNOREWARNING_GNUC(GCC diagnostic ignored w)
#    define CARB_IGNOREWARNING_GNUC_WITH_PUSH(w) CARB_IGNOREWARNING_GNUC_PUSH CARB_IGNOREWARNING_GNUC(w)
#    if CARB_TOOLCHAIN_CLANG
#        define CARB_IGNOREWARNING_CLANG_PUSH _Pragma("clang diagnostic push")
#        define CARB_IGNOREWARNING_CLANG_POP _Pragma("clang diagnostic pop")
#        define INTERNAL_CARB_IGNOREWARNING_CLANG(str) _Pragma(#        str)
#        define CARB_IGNOREWARNING_CLANG(w) INTERNAL_CARB_IGNOREWARNING_CLANG(clang diagnostic ignored w)
#        define CARB_IGNOREWARNING_CLANG_WITH_PUSH(w) CARB_IGNOREWARNING_CLANG_PUSH CARB_IGNOREWARNING_CLANG(w)
#    else
#        define CARB_IGNOREWARNING_CLANG_PUSH
#        define CARB_IGNOREWARNING_CLANG_POP
#        define CARB_IGNOREWARNING_CLANG(w)
#        define CARB_IGNOREWARNING_CLANG_WITH_PUSH(w)
#    endif
#else
#    define CARB_IGNOREWARNING_GNUC_PUSH
#    define CARB_IGNOREWARNING_GNUC_POP
#    define CARB_IGNOREWARNING_CLANG_PUSH
#    define CARB_IGNOREWARNING_CLANG_POP
#    define CARB_IGNOREWARNING_GNUC(w)
#    define CARB_IGNOREWARNING_GNUC_WITH_PUSH(w)
#    define CARB_IGNOREWARNING_CLANG(w)
#    define CARB_IGNOREWARNING_CLANG_WITH_PUSH(w)
#endif

#ifdef DOXYGEN_BUILD
#    define CARB_WARNING(msg)
#elif CARB_COMPILER_MSC
#    define CARB_WARNING(msg)                                                                                          \
        CARB_PRAGMA(message("\x1b[33m" __FILE__ ":" CARB_STRINGIFY(__LINE__) ": " msg "\x1b[0m"))                      \
        CARB_PRAGMA(warning_see_message)
#elif CARB_COMPILER_GNUC
// clang-format off
#    define CARB_WARNING(msg) CARB_PRAGMA(GCC warning #msg)
// clang-format on
#endif