Skip to content

Commit

Permalink
workaround for weird symbol issue on nvc++
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Mar 19, 2024
1 parent a851257 commit 1f7884e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ template:
-->

## Unreleased

## v3.4.0

- fixed "unresolved symbol" error with nvc++ (#220) (@Tomcat-42)

#### Fixes

- fixed `value_flags` not being preserved correctly when inserting into tables and arrays (#108) (@LebJe)
Expand Down
20 changes: 17 additions & 3 deletions include/toml++/impl/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#include "source_region.hpp"
#include "header_start.hpp"

// workaround for this: https://github.com/marzer/tomlplusplus/issues/220
#if TOML_NVCC
#define TOML_NVCC_WORKAROUND { return {}; }
#else
#define TOML_NVCC_WORKAROUND = 0
#endif

TOML_NAMESPACE_START
{
/// \brief A TOML node.
Expand Down Expand Up @@ -246,19 +253,19 @@ TOML_NAMESPACE_START

/// \brief Returns the node's type identifier.
TOML_PURE_GETTER
virtual node_type type() const noexcept = 0;
virtual node_type type() const noexcept TOML_NVCC_WORKAROUND;

/// \brief Returns true if this node is a table.
TOML_PURE_GETTER
virtual bool is_table() const noexcept = 0;
virtual bool is_table() const noexcept TOML_NVCC_WORKAROUND;

/// \brief Returns true if this node is an array.
TOML_PURE_GETTER
virtual bool is_array() const noexcept = 0;

/// \brief Returns true if this node is an array containing only tables.
TOML_PURE_GETTER
virtual bool is_array_of_tables() const noexcept = 0;
virtual bool is_array_of_tables() const noexcept TOML_NVCC_WORKAROUND;

/// \brief Returns true if this node is a value.
TOML_PURE_GETTER
Expand Down Expand Up @@ -327,6 +334,8 @@ TOML_NAMESPACE_START
return is_time();
else if constexpr (std::is_same_v<type, date_time>)
return is_date_time();

TOML_UNREACHABLE;
}

/// @}
Expand Down Expand Up @@ -452,6 +461,8 @@ TOML_NAMESPACE_START
return as_time();
else if constexpr (std::is_same_v<unwrapped_type, date_time>)
return as_date_time();

TOML_UNREACHABLE;
}

/// \brief Gets a pointer to the node as a more specific node type (const overload).
Expand Down Expand Up @@ -481,6 +492,8 @@ TOML_NAMESPACE_START
return as_time();
else if constexpr (std::is_same_v<unwrapped_type, date_time>)
return as_date_time();

TOML_UNREACHABLE;
}

/// @}
Expand Down Expand Up @@ -1112,4 +1125,5 @@ TOML_IMPL_NAMESPACE_START
TOML_IMPL_NAMESPACE_END;
/// \endcond

#undef TOML_NVCC_WORKAROUND
#include "header_end.hpp"
26 changes: 26 additions & 0 deletions include/toml++/impl/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@
#endif
#endif

#ifndef TOML_NVCC
#ifdef __NVCOMPILER_MAJOR__
#define TOML_NVCC __NVCOMPILER_MAJOR__
#else
#define TOML_NVCC 0
#endif
#endif

//#=====================================================================================================================
//# ARCHITECTURE
//#=====================================================================================================================
Expand Down Expand Up @@ -395,6 +403,7 @@
#endif

// TOML_ALWAYS_INLINE
#ifndef TOML_ALWAYS_INLINE
#ifdef _MSC_VER
#define TOML_ALWAYS_INLINE __forceinline
#elif TOML_GCC || TOML_CLANG || TOML_HAS_ATTR(__always_inline__)
Expand All @@ -404,8 +413,10 @@
#else
#define TOML_ALWAYS_INLINE inline
#endif
#endif

// TOML_NEVER_INLINE
#ifndef TOML_NEVER_INLINE
#ifdef _MSC_VER
#define TOML_NEVER_INLINE TOML_DECLSPEC(noinline)
#elif TOML_CUDA // https://gitlab.gnome.org/GNOME/glib/-/issues/2555
Expand All @@ -418,33 +429,44 @@
#ifndef TOML_NEVER_INLINE
#define TOML_NEVER_INLINE
#endif
#endif

// MSVC attributes
#ifndef TOML_ABSTRACT_INTERFACE
#define TOML_ABSTRACT_INTERFACE TOML_DECLSPEC(novtable)
#endif
#ifndef TOML_EMPTY_BASES
#define TOML_EMPTY_BASES TOML_DECLSPEC(empty_bases)
#endif

// TOML_TRIVIAL_ABI
#ifndef TOML_TRIVIAL_ABI
#if TOML_CLANG || TOML_HAS_ATTR(__trivial_abi__)
#define TOML_TRIVIAL_ABI TOML_ATTR(__trivial_abi__)
#else
#define TOML_TRIVIAL_ABI
#endif
#endif

// TOML_NODISCARD
#ifndef TOML_NODISCARD
#if TOML_CPP >= 17 && TOML_HAS_CPP_ATTR(nodiscard) >= 201603
#define TOML_NODISCARD [[nodiscard]]
#elif TOML_CLANG || TOML_GCC || TOML_HAS_ATTR(__warn_unused_result__)
#define TOML_NODISCARD TOML_ATTR(__warn_unused_result__)
#else
#define TOML_NODISCARD
#endif
#endif

// TOML_NODISCARD_CTOR
#ifndef TOML_NODISCARD_CTOR
#if TOML_CPP >= 17 && TOML_HAS_CPP_ATTR(nodiscard) >= 201907
#define TOML_NODISCARD_CTOR [[nodiscard]]
#else
#define TOML_NODISCARD_CTOR
#endif
#endif

// pure + const
#ifndef TOML_PURE
Expand Down Expand Up @@ -494,6 +516,7 @@
#endif

// TOML_ASSUME
#ifndef TOML_ASSUME
#ifdef _MSC_VER
#define TOML_ASSUME(expr) __assume(expr)
#elif TOML_ICC || TOML_CLANG || TOML_HAS_BUILTIN(__builtin_assume)
Expand All @@ -505,15 +528,18 @@
#else
#define TOML_ASSUME(expr) static_cast<void>(0)
#endif
#endif

// TOML_UNREACHABLE
#ifndef TOML_UNREACHABLE
#ifdef _MSC_VER
#define TOML_UNREACHABLE __assume(0)
#elif TOML_ICC || TOML_CLANG || TOML_GCC || TOML_HAS_BUILTIN(__builtin_unreachable)
#define TOML_UNREACHABLE __builtin_unreachable()
#else
#define TOML_UNREACHABLE static_cast<void>(0)
#endif
#endif

// TOML_LIKELY
#if TOML_CPP >= 20 && TOML_HAS_CPP_ATTR(likely) >= 201803
Expand Down
2 changes: 2 additions & 0 deletions include/toml++/impl/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,8 @@ TOML_NAMESPACE_START
}
return iterator{ ipos };
}

TOML_UNREACHABLE;
}

/// \brief Inserts a new value at a specific key if one did not already exist.
Expand Down
1 change: 0 additions & 1 deletion include/toml++/impl/toml_formatter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ TOML_ANON_NAMESPACE_START
val *= -1.0;
}
return weight + static_cast<size_t>(log10(val)) + 1u;
break;
}

case node_type::boolean: return 5u;
Expand Down
1 change: 1 addition & 0 deletions include/toml++/toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ TOML_POP_WARNINGS;
#undef TOML_NEVER_INLINE
#undef TOML_NODISCARD
#undef TOML_NODISCARD_CTOR
#undef TOML_NVCC
#undef TOML_OPEN_ENUM
#undef TOML_OPEN_FLAGS_ENUM
#undef TOML_PARSER_TYPENAME
Expand Down
Loading

0 comments on commit 1f7884e

Please sign in to comment.