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
11 changes: 9 additions & 2 deletions include/maul-unicode/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ extern "C"
// MUNI_NODISCARD marks a function whose result must be read: every
// function that returns a status. The attribute is standard in C23 and
// C++17 and left out for older dialects. MSVC keeps __cplusplus at
// 199711L unless /Zc:__cplusplus is given, so _MSVC_LANG is read too.
// 199711L unless /Zc:__cplusplus is given, so _MSVC_LANG is read too. In
// C, any dialect after C17 whose compiler has the attribute takes it:
// GCC 14 reports 202000L in its C23 mode.
#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
#define MUNI_NODISCARD [[nodiscard]]
#elif !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
#elif !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L && \
defined(__has_c_attribute)
#if __has_c_attribute(nodiscard)
#define MUNI_NODISCARD [[nodiscard]]
#else
#define MUNI_NODISCARD
#endif
#else
#define MUNI_NODISCARD
#endif

// The status a fallible function returns. Zero is success, positive
Expand Down
10 changes: 9 additions & 1 deletion test/test_base.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Sirac Ozmen
//
// Versions and result names, and the layouts of the public types.
// Versions, result names, the result attribute, and the layouts of the
// public types.

#include "test_harness.h"

Expand All @@ -18,6 +19,13 @@
#include <stddef.h>
#include <string.h>

// The suites build as C23, where every compiler the family takes has
// [[nodiscard]], so MUNI_NODISCARD expands to it and a dropped status
// warns (GCC 14 reports its C23 as 202000L).
#define TEXT(x) #x
#define EXPANDED(x) TEXT(x)
static_assert(sizeof(EXPANDED(MUNI_NODISCARD)) > 1, "MUNI_NODISCARD is the attribute in C23");

static void TestVersionMatchesHeader(void)
{
muniVersion version = muniGetVersion();
Expand Down
Loading