OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_ | 5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_ |
6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_ | 6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 // Annotate a variable indicating it's okay if it's unused. | 10 // Annotate a variable indicating it's okay if it's unused. |
11 // Use like: | 11 // Use like: |
12 // int x MOJO_ALLOW_UNUSED = ...; | 12 // int x MOJO_ALLOW_UNUSED = ...; |
13 #if defined(__GNUC__) | 13 #if defined(__GNUC__) |
14 #define MOJO_ALLOW_UNUSED __attribute__((unused)) | 14 #define MOJO_ALLOW_UNUSED __attribute__((unused)) |
Nico
2014/05/04 01:32:41
(Note that base's ignore_result() is a better way
| |
15 #else | 15 #else |
16 #define MOJO_ALLOW_UNUSED | 16 #define MOJO_ALLOW_UNUSED |
17 #endif | 17 #endif |
18 | 18 |
19 // Annotate a function indicating that the caller must examine the return value. | 19 // Annotate a function indicating that the caller must examine the return value. |
20 // Use like: | 20 // Use like: |
21 // int foo() MOJO_WARN_UNUSED_RESULT; | 21 // int foo() MOJO_WARN_UNUSED_RESULT; |
22 // Note that it can only be used on the prototype, and not the definition. | 22 // Note that it can only be used on the prototype, and not the definition. |
23 #if defined(__GNUC__) | 23 #if defined(__GNUC__) |
24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) | 24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
25 #else | 25 #else |
26 #define MOJO_WARN_UNUSED_RESULT | 26 #define MOJO_WARN_UNUSED_RESULT |
27 #endif | 27 #endif |
28 | 28 |
29 // This macro is currently C++-only, but we want to use it in the C core.h. | 29 // This macro is currently C++-only, but we want to use it in the C core.h. |
30 #ifdef __cplusplus | |
31 // Used to assert things at compile time. | 30 // Used to assert things at compile time. |
31 #if __cplusplus >= 201103L | |
darin (slow to review)
2014/05/04 03:15:15
this header is intended to be seen by a C compiler
Nico
2014/05/04 04:20:12
I think that's fine; undefined symbols evaluate to
| |
32 #define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) | |
33 #elif defined(__cplusplus) | |
32 namespace mojo { template <bool> struct CompileAssert {}; } | 34 namespace mojo { template <bool> struct CompileAssert {}; } |
33 #define MOJO_COMPILE_ASSERT(expr, msg) \ | 35 #define MOJO_COMPILE_ASSERT(expr, msg) \ |
34 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] | 36 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] |
35 #else | 37 #else |
36 #define MOJO_COMPILE_ASSERT(expr, msg) | 38 #define MOJO_COMPILE_ASSERT(expr, msg) |
37 #endif | 39 #endif |
38 | 40 |
39 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ | 41 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ |
OLD | NEW |