|
1 // 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. |
|
4 |
|
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 |
|
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. |
|
38 #define MSVC_POP_WARNING() __pragma(warning(pop)) |
|
39 |
|
40 #define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off)) |
|
41 #define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on)) |
|
42 |
|
43 // 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 // Not MSVC |
|
57 |
|
58 #define MSVC_SUPPRESS_WARNING(n) |
|
59 #define MSVC_PUSH_DISABLE_WARNING(n) |
|
60 #define MSVC_PUSH_WARNING_LEVEL(n) |
|
61 #define MSVC_POP_WARNING() |
|
62 #define MSVC_DISABLE_OPTIMIZE() |
|
63 #define MSVC_ENABLE_OPTIMIZE() |
|
64 #define ALLOW_THIS_IN_INITIALIZER_LIST(code) code |
|
65 |
|
66 #endif // COMPILER_MSVC |
|
67 |
|
68 |
|
69 #if defined(COMPILER_GCC) |
|
70 #define ALLOW_UNUSED __attribute__((unused)) |
|
71 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
|
72 #else // Not GCC |
|
73 #define ALLOW_UNUSED |
|
74 #define WARN_UNUSED_RESULT |
|
75 #endif |
|
76 |
|
77 #endif // BASE_COMPILER_SPECIFIC_H_ |