[vtk-developers] CLang woes with VTK5.8.0

kent williams nkwmailinglists at gmail.com
Fri Dec 30 10:30:35 EST 2011


I've been trying to build VTK & ITK with CLang as part of another
project, and run into a collision between two things CLang has a
problem with:

1. vnl_math.h has a large number of warnings because of in-class
definitions of static const float members.
2. vtkYoungsMaterialInterface.cxx has a macro ALLOC_LOCAL_ARRAY that
uses a Gnu C extenstion to define arrays with variable length.

To try and address #1, I add -Werror=gnu to the CLang compiler flags.
If this is set, the compiler test for in-line static const float
members fails, which gets rid of the gazillion warnings everywhere
vnl_math.h is included.

But this causes another problem (see #2) because
vtkYoungsMaterialInterface.cxx no longer compiles, as -Werror=gnu
makes all gnu extensions an error.

The real problem is that CLang defines __GNUC__ -- I would think that
if you make all the GNUC extensions errors, it would be a good idea of
CLang no longer defined __GNUC__.

Looking at the ALLOC_LOCAL_ARRAY macros, it looks like a simple patch
would fix things:

diff --git a/Graphics/vtkYoungsMaterialInterface.cxx
b/Graphics/vtkYoungsMaterialInterface.cxx
index a509a2b..407a83c 100644
--- a/Graphics/vtkYoungsMaterialInterface.cxx
+++ b/Graphics/vtkYoungsMaterialInterface.cxx
@@ -2049,7 +2049,7 @@ namespace vtkYoungsMaterialInterfaceCellCutInternals
   sdata += ROUND_SIZE( sizeof(type)*(n) )
 #define FREE_LOCAL_ARRAY(name,type,n) sdata -= ROUND_SIZE( sizeof(type)*(n) )

-#elif defined(__GNUC__) // Warning, this is a gcc extension, not all
compiler accept it
+#elif defined(__GNUC__) && !defined(__clang__) // Warning, this is a
gcc extension, not all compiler accept it
 #define ALLOC_LOCAL_ARRAY(name,type,n) type name[(n)]
 #define FREE_LOCAL_ARRAY(name,type,n)
 #else



More information about the vtk-developers mailing list