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. |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #ifdef __cplusplus | 29 #ifdef __cplusplus |
30 // Used to explicitly mark the return value of a function as unused. If you are | 30 // Used to explicitly mark the return value of a function as unused. If you are |
31 // really sure you don't want to do anything with the return value of a function | 31 // really sure you don't want to do anything with the return value of a function |
32 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: | 32 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: |
33 // | 33 // |
34 // scoped_ptr<MyType> my_var = ...; | 34 // scoped_ptr<MyType> my_var = ...; |
35 // if (TakeOwnership(my_var.get()) == SUCCESS) | 35 // if (TakeOwnership(my_var.get()) == SUCCESS) |
36 // mojo_ignore_result(my_var.release()); | 36 // mojo_ignore_result(my_var.release()); |
37 // | 37 // |
38 template<typename T> | 38 template <typename T> |
39 inline void mojo_ignore_result(const T&) { | 39 inline void mojo_ignore_result(const T&) { |
40 } | 40 } |
41 #endif | 41 #endif |
42 | 42 |
43 // Assert things at compile time. (|msg| should be a valid identifier name.) | 43 // Assert things at compile time. (|msg| should be a valid identifier name.) |
44 // This macro is currently C++-only, but we want to use it in the C core.h. | 44 // This macro is currently C++-only, but we want to use it in the C core.h. |
45 // Use like: | 45 // Use like: |
46 // MOJO_COMPILE_ASSERT(sizeof(Foo) == 12, Foo_has_invalid_size); | 46 // MOJO_COMPILE_ASSERT(sizeof(Foo) == 12, Foo_has_invalid_size); |
47 #if __cplusplus >= 201103L | 47 #if __cplusplus >= 201103L |
48 #define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) | 48 #define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) |
49 #elif defined(__cplusplus) | 49 #elif defined(__cplusplus) |
50 namespace mojo { template <bool> struct CompileAssert {}; } | 50 namespace mojo { |
| 51 template <bool> |
| 52 struct CompileAssert {}; |
| 53 } |
51 #define MOJO_COMPILE_ASSERT(expr, msg) \ | 54 #define MOJO_COMPILE_ASSERT(expr, msg) \ |
52 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] | 55 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] |
53 #else | 56 #else |
54 #define MOJO_COMPILE_ASSERT(expr, msg) | 57 #define MOJO_COMPILE_ASSERT(expr, msg) |
55 #endif | 58 #endif |
56 | 59 |
57 // Like the C++11 |alignof| operator. | 60 // Like the C++11 |alignof| operator. |
58 #if __cplusplus >= 201103L | 61 #if __cplusplus >= 201103L |
59 #define MOJO_ALIGNOF(type) alignof(type) | 62 #define MOJO_ALIGNOF(type) alignof(type) |
60 #elif defined(__GNUC__) | 63 #elif defined(__GNUC__) |
61 #define MOJO_ALIGNOF(type) __alignof__(type) | 64 #define MOJO_ALIGNOF(type) __alignof__(type) |
62 #elif defined(_MSC_VER) | 65 #elif defined(_MSC_VER) |
(...skipping 14 matching lines...) Expand all Loading... |
77 #define MOJO_ALIGNAS(alignment) alignas(alignment) | 80 #define MOJO_ALIGNAS(alignment) alignas(alignment) |
78 #elif defined(__GNUC__) | 81 #elif defined(__GNUC__) |
79 #define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment))) | 82 #define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment))) |
80 #elif defined(_MSC_VER) | 83 #elif defined(_MSC_VER) |
81 #define MOJO_ALIGNAS(alignment) __declspec(align(alignment)) | 84 #define MOJO_ALIGNAS(alignment) __declspec(align(alignment)) |
82 #else | 85 #else |
83 #error "Please define MOJO_ALIGNAS() for your compiler." | 86 #error "Please define MOJO_ALIGNAS() for your compiler." |
84 #endif | 87 #endif |
85 | 88 |
86 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ | 89 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ |
OLD | NEW |