blob: c9b753542e7e806a39cd1c7a1a5c7ee82127cacc [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]f1ea2fa2008-08-21 22:26:064
5#ifndef BASE_COMPILER_SPECIFIC_H_
6#define BASE_COMPILER_SPECIFIC_H_
7
8#include "build/build_config.h"
9
10#if defined(COMPILER_MSVC)
11
12// Macros for suppressing and disabling warnings on MSVC.
13//
14// Warning numbers are enumerated at:
15// http://msdn.microsoft.com/en-us/library/8x5x43k7(VS.80).aspx
16//
17// The warning pragma:
18// http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
19//
20// Using __pragma instead of #pragma inside macros:
21// http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
22
23// MSVC_SUPPRESS_WARNING disables warning |n| for the remainder of the line and
24// for the next line of the source file.
25#define MSVC_SUPPRESS_WARNING(n) __pragma(warning(suppress:n))
26
27// MSVC_PUSH_DISABLE_WARNING pushes |n| onto a stack of warnings to be disabled.
28// The warning remains disabled until popped by MSVC_POP_WARNING.
29#define MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \
30 __pragma(warning(disable:n))
[email protected]b91902d2008-09-16 19:28:0631
32// MSVC_PUSH_WARNING_LEVEL pushes |n| as the global warning level. The level
33// remains in effect until popped by MSVC_POP_WARNING(). Use 0 to disable all
34// warnings.
35#define MSVC_PUSH_WARNING_LEVEL(n) __pragma(warning(push, n))
36
37// Pop effects of innermost MSVC_PUSH_* macro.
[email protected]f1ea2fa2008-08-21 22:26:0638#define MSVC_POP_WARNING() __pragma(warning(pop))
39
[email protected]0eb9f4342008-11-21 18:48:5240#define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off))
41#define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on))
42
[email protected]f1ea2fa2008-08-21 22:26:0643// Allows |this| to be passed as an argument in constructor initializer lists.
44// This uses push/pop instead of the seemingly simpler suppress feature to avoid
45// having the warning be disabled for more than just |code|.
46//
47// Example usage:
48// Foo::Foo() : x(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)), z(3) {}
49//
50// Compiler warning C4355: 'this': used in base member initializer list:
51// http://msdn.microsoft.com/en-us/library/3c594ae3(VS.80).aspx
52#define ALLOW_THIS_IN_INITIALIZER_LIST(code) MSVC_PUSH_DISABLE_WARNING(4355) \
53 code \
54 MSVC_POP_WARNING()
55
56#else // COMPILER_MSVC
57
58#define MSVC_SUPPRESS_WARNING(n)
59#define MSVC_PUSH_DISABLE_WARNING(n)
[email protected]b91902d2008-09-16 19:28:0660#define MSVC_PUSH_WARNING_LEVEL(n)
[email protected]f1ea2fa2008-08-21 22:26:0661#define MSVC_POP_WARNING()
[email protected]0eb9f4342008-11-21 18:48:5262#define MSVC_DISABLE_OPTIMIZE()
63#define MSVC_ENABLE_OPTIMIZE()
[email protected]f1ea2fa2008-08-21 22:26:0664#define ALLOW_THIS_IN_INITIALIZER_LIST(code) code
65
66#endif // COMPILER_MSVC
67
68#endif // BASE_COMPILER_SPECIFIC_H_
license.botbf09a502008-08-24 00:55:5569