michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_COMPILER_SPECIFIC_H_ michael@0: #define BASE_COMPILER_SPECIFIC_H_ michael@0: michael@0: #include "build/build_config.h" michael@0: michael@0: #if defined(COMPILER_MSVC) michael@0: michael@0: // Macros for suppressing and disabling warnings on MSVC. michael@0: // michael@0: // Warning numbers are enumerated at: michael@0: // http://msdn.microsoft.com/en-us/library/8x5x43k7(VS.80).aspx michael@0: // michael@0: // The warning pragma: michael@0: // http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx michael@0: // michael@0: // Using __pragma instead of #pragma inside macros: michael@0: // http://msdn.microsoft.com/en-us/library/d9x1s805.aspx michael@0: michael@0: // MSVC_SUPPRESS_WARNING disables warning |n| for the remainder of the line and michael@0: // for the next line of the source file. michael@0: #define MSVC_SUPPRESS_WARNING(n) __pragma(warning(suppress:n)) michael@0: michael@0: // MSVC_PUSH_DISABLE_WARNING pushes |n| onto a stack of warnings to be disabled. michael@0: // The warning remains disabled until popped by MSVC_POP_WARNING. michael@0: #define MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \ michael@0: __pragma(warning(disable:n)) michael@0: michael@0: // MSVC_PUSH_WARNING_LEVEL pushes |n| as the global warning level. The level michael@0: // remains in effect until popped by MSVC_POP_WARNING(). Use 0 to disable all michael@0: // warnings. michael@0: #define MSVC_PUSH_WARNING_LEVEL(n) __pragma(warning(push, n)) michael@0: michael@0: // Pop effects of innermost MSVC_PUSH_* macro. michael@0: #define MSVC_POP_WARNING() __pragma(warning(pop)) michael@0: michael@0: #define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off)) michael@0: #define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on)) michael@0: michael@0: // Allows |this| to be passed as an argument in constructor initializer lists. michael@0: // This uses push/pop instead of the seemingly simpler suppress feature to avoid michael@0: // having the warning be disabled for more than just |code|. michael@0: // michael@0: // Example usage: michael@0: // Foo::Foo() : x(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)), z(3) {} michael@0: // michael@0: // Compiler warning C4355: 'this': used in base member initializer list: michael@0: // http://msdn.microsoft.com/en-us/library/3c594ae3(VS.80).aspx michael@0: #define ALLOW_THIS_IN_INITIALIZER_LIST(code) MSVC_PUSH_DISABLE_WARNING(4355) \ michael@0: code \ michael@0: MSVC_POP_WARNING() michael@0: michael@0: #else // Not MSVC michael@0: michael@0: #define MSVC_SUPPRESS_WARNING(n) michael@0: #define MSVC_PUSH_DISABLE_WARNING(n) michael@0: #define MSVC_PUSH_WARNING_LEVEL(n) michael@0: #define MSVC_POP_WARNING() michael@0: #define MSVC_DISABLE_OPTIMIZE() michael@0: #define MSVC_ENABLE_OPTIMIZE() michael@0: #define ALLOW_THIS_IN_INITIALIZER_LIST(code) code michael@0: michael@0: #endif // COMPILER_MSVC michael@0: michael@0: michael@0: #if defined(COMPILER_GCC) michael@0: #define ALLOW_UNUSED __attribute__((unused)) michael@0: #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) michael@0: #else // Not GCC michael@0: #define ALLOW_UNUSED michael@0: #define WARN_UNUSED_RESULT michael@0: #endif michael@0: michael@0: #endif // BASE_COMPILER_SPECIFIC_H_