summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-08-26 15:03:22 +0200
committerGitHub <noreply@github.com>2018-08-26 15:03:22 +0200
commit42f36d1ee5dcc89e288c6ac128be0ff6ed0985e0 (patch)
tree4b164ce3b338c216787403e79898facb00834231
parent234189f34e5f055c82654b8cd35330822e8aa4d7 (diff)
parent4da22050a04f9cd45097dbdc678ab20971f5570b (diff)
downloadhercules-42f36d1ee5dcc89e288c6ac128be0ff6ed0985e0.tar.gz
hercules-42f36d1ee5dcc89e288c6ac128be0ff6ed0985e0.tar.bz2
hercules-42f36d1ee5dcc89e288c6ac128be0ff6ed0985e0.tar.xz
hercules-42f36d1ee5dcc89e288c6ac128be0ff6ed0985e0.zip
Merge pull request #2189 from MishimaHaruna/c11
Change the language specification to C11 in the autoconf-based builds
-rwxr-xr-xconfigure47
-rw-r--r--configure.ac32
-rw-r--r--src/common/cbasetypes.h6
-rw-r--r--src/common/strlib.h21
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/npc.c2
6 files changed, 99 insertions, 11 deletions
diff --git a/configure b/configure
index 3a33cebd3..180fe971d 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.ac 515eed8ee.
+# From configure.ac 234189f34.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69.
#
@@ -4776,7 +4776,50 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# -Werror-implicit-function-declaration -Wtrampolines
# -Wjump-misses-init
-CFLAGS="$CFLAGS -pipe -ffast-math -Wall -Wextra -Wno-sign-compare -std=c99"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c11" >&5
+$as_echo_n "checking whether $CC supports -std=c11... " >&6; }
+OLD_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -std=c11"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int foo;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+else
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c1x" >&5
+$as_echo_n "checking whether $CC supports -std=c1x... " >&6; }
+ CFLAGS="$OLD_CFLAGS -std=c1x"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int foo;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+else
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, falling back to -std=c99" >&5
+$as_echo "no, falling back to -std=c99" >&6; }
+ CFLAGS="$OLD_CFLAGS -std=c99"
+
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+CFLAGS="$CFLAGS -pipe -ffast-math -Wall -Wextra -Wno-sign-compare"
CPPFLAGS="$CPPFLAGS -I../common"
LDFLAGS="$LDFLAGS"
diff --git a/configure.ac b/configure.ac
index 1bb30b09f..4d5f4bcfd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -638,7 +638,37 @@ AC_LANG([C])
# -Werror-implicit-function-declaration -Wtrampolines
# -Wjump-misses-init
-CFLAGS="$CFLAGS -pipe -ffast-math -Wall -Wextra -Wno-sign-compare -std=c99"
+AC_MSG_CHECKING([whether $CC supports -std=c11])
+OLD_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -std=c11"
+AC_COMPILE_IFELSE(
+ [AC_LANG_SOURCE([int foo;])],
+ [
+ AC_MSG_RESULT([yes])
+ ],
+ [
+ AC_MSG_RESULT([no])
+
+ AC_MSG_CHECKING([whether $CC supports -std=c1x])
+ CFLAGS="$OLD_CFLAGS -std=c1x"
+ AC_COMPILE_IFELSE(
+ [AC_LANG_SOURCE([int foo;])],
+ [
+ AC_MSG_RESULT([yes])
+ ],
+ [
+ AC_MSG_RESULT([no, falling back to -std=c99])
+ CFLAGS="$OLD_CFLAGS -std=c99"
+ ]
+ )
+ ],
+ [
+ AC_MSG_RESULT([guessing no])
+ CFLAGS="$OLD_CFLAGS -std=c99"
+ ]
+)
+
+CFLAGS="$CFLAGS -pipe -ffast-math -Wall -Wextra -Wno-sign-compare"
CPPFLAGS="$CPPFLAGS -I../common"
LDFLAGS="$LDFLAGS"
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index 3fc41bb23..89f7f8588 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -460,12 +460,6 @@ typedef char bool;
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
// C11 version
#define STATIC_ASSERT(ex, msg) _Static_assert(ex, msg)
-#elif __has_feature(c_static_assert)
-// Clang support (as per http://clang.llvm.org/docs/LanguageExtensions.html)
-#define STATIC_ASSERT(ex, msg) _Static_assert(ex, msg)
-#elif defined(__GNUC__) && GCC_VERSION >= 40700
-// GCC >= 4.7 is known to support it
-#define STATIC_ASSERT(ex, msg) _Static_assert(ex, msg)
#elif defined(_MSC_VER)
// MSVC doesn't support it, but it accepts the C++ style version
#define STATIC_ASSERT(ex, msg) static_assert(ex, msg)
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 5ea4f4763..006bbd14b 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -49,6 +49,27 @@
#define safesnprintf(buf,sz,fmt,...) (strlib->safesnprintf_((buf),(sz),(fmt),##__VA_ARGS__))
#define strline(str,pos) (strlib->strline_((str),(pos)))
#define bin2hex(output,input,count) (strlib->bin2hex_((output),(input),(count)))
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
+#if defined(__GNUC__) && !defined(__clang__) && GCC_VERSION < 40900
+// _Generic is only supported starting with GCC 4.9
+#else
+#ifdef strchr
+#undef strchr
+#endif // strchr
+#define strchr(src, chr) _Generic((src), \
+ const char * : ((const char *)(strchr)((src), (chr))), \
+ char * : ((strchr)((src), (chr))) \
+ )
+#define strrchr(src, chr) _Generic((src), \
+ const char * : ((const char *)(strrchr)((src), (chr))), \
+ char * : ((strrchr)((src), (chr))) \
+ )
+#define strstr(haystack, needle) _Generic((haystack), \
+ const char * : ((const char *)(strstr)((haystack), (needle))), \
+ char * : ((strstr)((haystack), (needle))) \
+ )
+#endif
+#endif
/// Bitfield determining the behavior of sv_parse and sv_split.
typedef enum e_svopt {
diff --git a/src/map/clif.c b/src/map/clif.c
index fd8a3c783..a5955a9bc 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10891,7 +10891,7 @@ static void clif_parse_WisMessage(int fd, struct map_session_data *sd)
// Lordalfa - Paperboy - To whisper NPC commands //
//-------------------------------------------------------//
if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4)) {
- const char *str = target+4; //Skip the NPC: string part.
+ char *str = target + 4; // Skip the NPC: string part.
struct npc_data *nd;
if ((nd = npc->name2id(str))) {
char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
diff --git a/src/map/npc.c b/src/map/npc.c
index f80f8443a..a49fb08eb 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2868,7 +2868,7 @@ static const char *npc_parse_shop(const char *w1, const char *w2, const char *w3
struct npc_item_list *items = NULL;
size_t items_count = 40; // Starting items size
- char *p;
+ const char *p;
int x, y, dir, m, i, class_;
struct npc_data *nd;
enum npc_subtype type;