Tweak/Wontfix a few tests that we could care less about.
[chromium-blink-merge.git] / base / compiler_specific.h
blob23b9f1242364c9708c8cdadb58476a821f84ccd8
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.
5 #ifndef BASE_COMPILER_SPECIFIC_H_
6 #define BASE_COMPILER_SPECIFIC_H_
8 #include "build/build_config.h"
10 #if defined(COMPILER_MSVC)
12 // Macros for suppressing and disabling warnings on MSVC.
14 // Warning numbers are enumerated at:
15 // http://msdn.microsoft.com/en-us/library/8x5x43k7(VS.80).aspx
17 // The warning pragma:
18 // http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
20 // Using __pragma instead of #pragma inside macros:
21 // http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
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))
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))
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))
37 // Pop effects of innermost MSVC_PUSH_* macro.
38 #define MSVC_POP_WARNING() __pragma(warning(pop))
40 #define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off))
41 #define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on))
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|.
47 // Example usage:
48 // Foo::Foo() : x(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)), z(3) {}
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()
56 #else // Not MSVC
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
66 #endif // COMPILER_MSVC
69 #if defined(COMPILER_GCC)
71 #define ALLOW_UNUSED __attribute__((unused))
72 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
74 // Tell the compiler a function is using a printf-style format string.
75 // |format_param| is the one-based index of the format string parameter;
76 // |dots_param| is the one-based index of the "..." parameter.
77 // For v*printf functions (which take a va_list), pass 0 for dots_param.
78 // (This is undocumented but matches what the system C headers do.)
79 #define PRINTF_FORMAT(format_param, dots_param) \
80 __attribute__((format(printf, format_param, dots_param)))
82 // WPRINTF_FORMAT is the same, but for wide format strings.
83 // This doesn't appear to yet be implemented.
84 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 .
85 #define WPRINTF_FORMAT(format_param, dots_param)
86 // If available, it would look like:
87 // __attribute__((format(wprintf, format_param, dots_param)))
89 #else // Not GCC
91 #define ALLOW_UNUSED
92 #define WARN_UNUSED_RESULT
93 #define PRINTF_FORMAT(x, y)
94 #define WPRINTF_FORMAT(x, y)
96 #endif
98 #endif // BASE_COMPILER_SPECIFIC_H_