blob: 0043dd87af051b61e11bae90f500174c138ac1de [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.
mmentovai@google.comfa5f9932008-08-22 07:26:06 +09004
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))
31#define MSVC_POP_WARNING() __pragma(warning(pop))
32
33// Allows |this| to be passed as an argument in constructor initializer lists.
34// This uses push/pop instead of the seemingly simpler suppress feature to avoid
35// having the warning be disabled for more than just |code|.
36//
37// Example usage:
38// Foo::Foo() : x(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)), z(3) {}
39//
40// Compiler warning C4355: 'this': used in base member initializer list:
41// http://msdn.microsoft.com/en-us/library/3c594ae3(VS.80).aspx
42#define ALLOW_THIS_IN_INITIALIZER_LIST(code) MSVC_PUSH_DISABLE_WARNING(4355) \
43 code \
44 MSVC_POP_WARNING()
45
46#else // COMPILER_MSVC
47
48#define MSVC_SUPPRESS_WARNING(n)
49#define MSVC_PUSH_DISABLE_WARNING(n)
50#define MSVC_POP_WARNING()
51#define ALLOW_THIS_IN_INITIALIZER_LIST(code) code
52
53#endif // COMPILER_MSVC
54
55#endif // BASE_COMPILER_SPECIFIC_H_
license.botf003cfe2008-08-24 09:55:55 +090056