Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions common/include/nodiscard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2024 Intel Corporation
* Mariusz Zaborski <oshogbo@invisiblethingslab.com>
*/

/*
* This file contains a definition for NODISCARD, a macro that wraps
* 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 the macros and use [[nodiscard]] directly, after dropping *EL8
* and Ubuntu 20.04 support.
*/

#pragma once

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

#ifndef NODISCARD
#define NODISCARD
#endif
3 changes: 2 additions & 1 deletion common/include/pal_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#pragma once

#include <nodiscard.h>
#include <stddef.h>

typedef enum _pal_error_t {
typedef enum NODISCARD {
PAL_ERROR_SUCCESS = 0,
PAL_ERROR_NOTIMPLEMENTED,
PAL_ERROR_NOTDEFINED,
Expand Down
12 changes: 12 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ project(
],
)

# If C23 (or experimetal C23 - C2x) is available, use it.
# 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
# least gcc 14).
if meson.get_compiler('c').has_argument('-std=c23')
add_project_arguments('-std=c23', language: 'c')
elif meson.get_compiler('c').has_argument('-std=c2x')
add_project_arguments('-std=c2x', language: 'c')
endif

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

Expand Down