summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPeter0x44 <[email protected]>2023-06-01 08:47:52 +0100
committerGitHub <[email protected]>2023-06-01 09:47:52 +0200
commit2dec56e7b772ce4734f415e03715d0712ae68b8a (patch)
tree1cbddc6855ae8366da9cff553ab18baadcde62d3
parente497603678823dc93f01dd9686819a92d780ad67 (diff)
downloadraylib-2dec56e7b772ce4734f415e03715d0712ae68b8a.tar.gz
raylib-2dec56e7b772ce4734f415e03715d0712ae68b8a.zip
Add error if raylib.h is included in a C++98 program (#3093)
The color macros don't work properly in C++98, because they require aggregate initialzation, which is a C++11 feature. So, explicitly state how to fix this issue, instead of letting the compiler give a more vague error message like: main.cpp:8:23: error: expected '(' for function-style cast or type construction ClearBackground(BLACK); ^~~~~ /opt/homebrew/Cellar/raylib/4.5.0/include/raylib.h:179:35: note: expanded from macro 'BLACK' #define BLACK CLITERAL(Color){ 0, 0, 0, 255 } // Black NOTE: Don't use this check with MSVC because by default, it reports 199711L regardless of any C++ version passed on command line Only passing `/Zc:__cplusplus` will make MSVC set this correctly see: https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
-rw-r--r--src/raylib.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/raylib.h b/src/raylib.h
index b2b82583..56acd6ad 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -133,12 +133,20 @@
// NOTE: MSVC C++ compiler does not support compound literals (C99 feature)
// Plain structures in C++ (without constructors) can be initialized with { }
+// This is called aggregate initialization (C++11 feature)
#if defined(__cplusplus)
#define CLITERAL(type) type
#else
#define CLITERAL(type) (type)
#endif
+// Some compilers (mostly macos clang) default to C++98,
+// where aggregate initialization can't be used
+// So, give a more clear error stating how to fix this
+#if !defined(_MSC_VER) && (defined(__cplusplus) && __cplusplus < 201103L)
+ #error "C++11 or later is required. Add -std=c++11"
+#endif
+
// NOTE: We set some defines with some data types declared by raylib
// Other modules (raymath, rlgl) also require some of those types, so,
// to be able to use those other modules as standalone (not depending on raylib)