Skip to content

Commit

Permalink
fixup! [meson,common] Enable C23 and nodiscard feature when available
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Zaborski <[email protected]>
  • Loading branch information
oshogbo committed May 14, 2024
1 parent ab24fbc commit d7a0b9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 3 additions & 6 deletions common/include/nodiscard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
* the nodiscard attribute introduced in C23. However, because Gramine supports
* older systems that might not have support for C23, we have to wrap it on our
* own and change it to a no-op on systems that don't support it.
* TODO: Remove this after dropping *EL8 and Ubuntu 20.04 support.
*/

#pragma once

#if defined(__has_c_attribute)
#if __has_c_attribute(nodiscard)
#if GRAMINE_HAS_NODISCARD
#define NODISCARD [[nodiscard]]
#endif
#endif

#ifndef NODISCARD
#else
#define NODISCARD
#endif
22 changes: 18 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ project(
)

# If C23 (or experimetal C23 - C2x) is available, use it.
# XXX: Gramine supports older versions of Ubuntu, so newer versions of compilers
# may not be available.
if meson.get_compiler('c').has_argument('-std=c23')
# TODO: Gramine supports older versions of gcc, so newer versions of compilers
# may not be available.
# We can change to c2x when we drop *EL8 and Ubuntu 20.04.
# We can't change to c23 for any supported versions yet (requires at
# leaast gcc 14).
nodiscard_code = '[[nodiscard]] int func() { return 0; }'
if meson.get_compiler('c').compiles(
nodiscard_code,
args : '-std=c23',
name : 'check for [[nodiscard]] and c23',
)
add_project_arguments('-std=c23', language: 'c')
elif meson.get_compiler('c').has_argument('-std=c2x')
add_global_arguments('-DGRAMINE_HAS_NODISCARD', language : 'c')
elif meson.get_compiler('c').compiles(
nodiscard_code,
args : '-std=c2x',
name : 'check for [[nodiscard]] and c2x',
)
add_project_arguments('-std=c2x', language: 'c')
add_global_arguments('-DGRAMINE_HAS_NODISCARD', language : 'c')
endif

# we need this subdir() early, because we need scripts defined there for setting up global vars
Expand Down

0 comments on commit d7a0b9c

Please sign in to comment.