Dune Core Modules (unstable)

forceinline.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_COMMON_FORCEINLINE_HH
6#define DUNE_COMMON_FORCEINLINE_HH
7
35#if defined(__clang__)
36 // Clang does not generate an error for non-inlinable `always_inline` functions.
37 #define DUNE_FORCE_INLINE __attribute__((always_inline)) inline
38
39#elif defined(__GNUC__)
40 // GCC would generate an error if it can't always_inline
41 #define DUNE_FORCE_INLINE __attribute__((always_inline)) inline
42
43#elif defined(_MSC_VER)
44 // MSVC generates a warning for for non-inlinable `__forceinline` functions. But
45 // only if compiled with any "inline expansion" optimization (`/Ob<n>`). This is
46 // present with `/O1` or `/O2`. We promote this warning to an error.
47 #pragma warning(error: 4714)
48 #define DUNE_FORCE_INLINE [[msvc::forceinline]]
49
50#else
51 // fallback to `inline` in case the compiler cannot be detected.
52 #define DUNE_FORCE_INLINE inline
53#endif
54
55#endif // DUNE_COMMON_FORCEINLINE_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Nov 2, 23:43, 2025)