[Bf-blender-cvs] [4ff0126] master: C99 is now the C standard for all our C code.

Brecht Van Lommel noreply at git.blender.org
Sun Nov 22 22:32:36 CET 2015


Commit: 4ff0126e890cebe16b4eec5c1b2bc507346b4f24
Author: Brecht Van Lommel
Date:   Sun Nov 22 17:12:54 2015 +0100
Branches: master
https://developer.blender.org/rB4ff0126e890cebe16b4eec5c1b2bc507346b4f24

C99 is now the C standard for all our C code.

The main new feature is mixed variable declarations and code, which can help
reduce uninitialized variables or accidental variable reuse.

Due to incomplete C99 support in VS 2013, variable length arrays are not
supported, BLI_array_alloca must still be used. The header <tgmath.h> is also
not supported.

Differential Revision: https://developer.blender.org/D1631

===================================================================

M	CMakeLists.txt
M	SConstruct
M	build_files/scons/config/darwin-config.py
M	build_files/scons/config/linux-config.py
M	build_files/scons/config/win32-mingw-config.py
M	build_files/scons/config/win64-mingw-config.py
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/python/mathutils/mathutils_Matrix.c

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 14eb2af..b5317cc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1189,12 +1189,6 @@ if(UNIX AND NOT APPLE)
 	if(CMAKE_COMPILER_IS_GNUCC)
 		set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
 
-		if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "5.0")
-			# GCC5 uses gnu11, until we update, force c89
-			# though some c11 features can still be used.
-			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
-		endif()
-
 		# use ld.gold linker if available, could make optional
 		execute_process(
 		        COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
@@ -2577,9 +2571,9 @@ if(CMAKE_COMPILER_IS_GNUCC)
 
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
-	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
+	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
 	# system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
@@ -2624,7 +2618,6 @@ if(CMAKE_COMPILER_IS_GNUCC)
 	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
 	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
 	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
-	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
 	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
 	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
 	ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
@@ -2661,7 +2654,6 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
 
 	# strange, clang complains these are not supported, but then yses them.
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
-	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
 	ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
@@ -2776,6 +2768,13 @@ if(WITH_CPP11)
 	endif()
 endif()
 
+if(MSVC)
+	# Visual Studio has all standards it supports available by default
+else()
+	# Use C99 + GNU extensions, works with GCC, Clang, ICC
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+endif()
+
 # Include warnings first, so its possible to disable them with user defined flags
 # eg: -Wno-uninitialized
 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
diff --git a/SConstruct b/SConstruct
index ebd9cd1..29f5392 100644
--- a/SConstruct
+++ b/SConstruct
@@ -498,6 +498,13 @@ if env['WITH_BF_CPP11']:
     else:
         env['CXXFLAGS'].append('-std=c++11')
 
+if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
+    # Visual Studio has all standards it supports available by default
+    pass
+else:
+    # Use C99 + GNU extensions, works with GCC, Clang, ICC
+    env['CFLAGS'].append('-std=gnu99')
+
 #check for additional debug libnames
 
 if env.has_key('BF_DEBUG_LIBS'):
diff --git a/build_files/scons/config/darwin-config.py b/build_files/scons/config/darwin-config.py
index 0bf03a4..16ba3ec 100644
--- a/build_files/scons/config/darwin-config.py
+++ b/build_files/scons/config/darwin-config.py
@@ -248,7 +248,7 @@ REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2']
 
 CC_WARN = ['-Wall']
-C_WARN = ['-Wno-char-subscripts', '-Wpointer-arith', '-Wcast-align', '-Wdeclaration-after-statement', '-Wno-unknown-pragmas', '-Wstrict-prototypes']
+C_WARN = ['-Wno-char-subscripts', '-Wpointer-arith', '-Wcast-align', '-Wvla', '-Wno-unknown-pragmas', '-Wstrict-prototypes']
 CXX_WARN = ['-Wno-invalid-offsetof', '-Wno-sign-compare']
 
 ##FIX_STUBS_WARNINGS = -Wno-unused
diff --git a/build_files/scons/config/linux-config.py b/build_files/scons/config/linux-config.py
index ff8ecf0..1990d6e 100644
--- a/build_files/scons/config/linux-config.py
+++ b/build_files/scons/config/linux-config.py
@@ -254,7 +254,7 @@ REL_CFLAGS = []
 REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2']
 
-C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wunused-parameter', '-Wstrict-prototypes', '-Werror=declaration-after-statement', '-Werror=implicit-function-declaration', '-Werror=return-type']
+C_WARN = ['-Wno-char-subscripts', '-Wvla', '-Wunused-parameter', '-Wstrict-prototypes', '-Werror=vla', '-Werror=implicit-function-declaration', '-Werror=return-type']
 CC_WARN = ['-Wall']
 CXX_WARN = ['-Wno-invalid-offsetof', '-Wno-sign-compare']
 
diff --git a/build_files/scons/config/win32-mingw-config.py b/build_files/scons/config/win32-mingw-config.py
index 552a1a5..f4b709d 100644
--- a/build_files/scons/config/win32-mingw-config.py
+++ b/build_files/scons/config/win32-mingw-config.py
@@ -202,7 +202,7 @@ REL_CFLAGS = []
 REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2']
 
-C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wstrict-prototypes']
+C_WARN = ['-Wno-char-subscripts', '-Wvla', '-Wstrict-prototypes']
 
 CC_WARN = [ '-Wall' ]
 
diff --git a/build_files/scons/config/win64-mingw-config.py b/build_files/scons/config/win64-mingw-config.py
index 87a9b5e..6106f2a 100644
--- a/build_files/scons/config/win64-mingw-config.py
+++ b/build_files/scons/config/win64-mingw-config.py
@@ -197,7 +197,7 @@ REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2', '-ftree-vectorize']
 
 # NOTE: C_WARN seems to get ignored - at least -Wno-char-subscripts doesn't work!
-C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wstrict-prototypes']
+C_WARN = ['-Wno-char-subscripts', '-Wvla', '-Wstrict-prototypes']
 
 CC_WARN = [ '-Wall', '-Wno-char-subscripts' ]
 
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index b7742d8..57e37c0 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -30,6 +30,9 @@
  */
 
 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#  ifdef __GNUC__
+#    pragma GCC diagnostic ignored "-Wvla"
+#  endif
 #  define USE_DYNSIZE
 #endif
 
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 7ad20d4..7128887 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -2055,7 +2055,7 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
 
 static Py_hash_t Matrix_hash(MatrixObject *self)
 {
-	float mat[SQUARE(MATRIX_MAX_DIM)];
+	float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
 
 	if (BaseMath_ReadCallback(self) == -1)
 		return -1;




More information about the Bf-blender-cvs mailing list