Skip to content

Commit 703af8d

Browse files
committed
mbed_toolchain: Use C++11/C11 attributes
Newer language standards have standard forms for `MBED_NORETURN` and `MBED_ALIGN` attributes. Use them when available. C++14 also adds `[[deprecated]]`, but as it needs to go in the middle of structure definitions as `class [[deprecated]] MyClass`, it's not a total drop-in-replacemend for `MBED_DEPRECATED`, so that is not attempted here. Using standard forms increases the chances that code analysis tools such Coverity will recognise them - particularly important for "no return".
1 parent 56a043c commit 703af8d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

platform/mbed_toolchain.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@
7272
* @endcode
7373
*/
7474
#ifndef MBED_ALIGN
75-
#if defined(__ICCARM__)
75+
#if __cplusplus >= 201103 && !defined __CC_ARM
76+
#define MBED_ALIGN(N) alignas(N)
77+
#elif __STDC_VERSION__ >= 201112 && !defined __CC_ARM
78+
#define MBED_ALIGN(N) _Alignas(N)
79+
#elif defined(__ICCARM__)
7680
#define MBED_ALIGN(N) _Pragma(MBED_STRINGIFY(data_alignment=N))
7781
#else
7882
#define MBED_ALIGN(N) __attribute__((aligned(N)))
@@ -298,7 +302,11 @@
298302
* @endcode
299303
*/
300304
#ifndef MBED_NORETURN
301-
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
305+
#if __cplusplus >= 201103
306+
#define MBED_NORETURN [[noreturn]]
307+
#elif __STDC_VERSION__ >= 201112
308+
#define MBED_NORETURN _Noreturn
309+
#elif defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
302310
#define MBED_NORETURN __attribute__((noreturn))
303311
#elif defined(__ICCARM__)
304312
#define MBED_NORETURN __noreturn

0 commit comments

Comments
 (0)