Skip to content

Commit

Permalink
Only use noexcept in public headers on >= C++11 (#1071)
Browse files Browse the repository at this point in the history
This resolves issues consuming openal-soft in projects that don't
explicitly specify a C++ standard of C++11 or newer.

This also handles the fact that __cplusplus is not set properly in MSVC
(always claiming to be 199711L) which prevented both the C++11 noexcept
and the C++17 noexcept annotations from taking effect.
  • Loading branch information
dpogue authored Nov 24, 2024
1 parent e47b707 commit 6854a57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion include/AL/al.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
#ifdef __cplusplus
extern "C" {

#ifdef _MSVC_LANG
#define AL_CPLUSPLUS _MSVC_LANG
#else
#define AL_CPLUSPLUS __cplusplus
#endif

#ifndef AL_DISABLE_NOEXCEPT
#if AL_CPLUSPLUS >= 201103L
#define AL_API_NOEXCEPT noexcept
#if __cplusplus >= 201703L
#else
#define AL_API_NOEXCEPT
#endif
#if AL_CPLUSPLUS >= 201703L
#define AL_API_NOEXCEPT17 noexcept
#else
#define AL_API_NOEXCEPT17
Expand All @@ -19,6 +29,8 @@ extern "C" {
#define AL_API_NOEXCEPT17
#endif

#undef AL_CPLUSPLUS

#else /* __cplusplus */

#define AL_API_NOEXCEPT
Expand Down
14 changes: 13 additions & 1 deletion include/AL/alc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
#ifdef __cplusplus
extern "C" {

#ifdef _MSVC_LANG
#define ALC_CPLUSPLUS _MSVC_LANG
#else
#define ALC_CPLUSPLUS __cplusplus
#endif

#ifndef AL_DISABLE_NOEXCEPT
#if ALC_CPLUSPLUS >= 201103L
#define ALC_API_NOEXCEPT noexcept
#if __cplusplus >= 201703L
#else
#define ALC_API_NOEXCEPT
#endif
#if ALC_CPLUSPLUS >= 201703L
#define ALC_API_NOEXCEPT17 noexcept
#else
#define ALC_API_NOEXCEPT17
Expand All @@ -19,6 +29,8 @@ extern "C" {
#define ALC_API_NOEXCEPT17
#endif

#undef ALC_CPLUSPLUS

#else /* __cplusplus */

#define ALC_API_NOEXCEPT
Expand Down

0 comments on commit 6854a57

Please sign in to comment.