Skip to content

Commit

Permalink
COMP: fix build with -std=c++11 when ITK/VXL initially configured wit…
Browse files Browse the repository at this point in the history
…hout

SimpleITK forces the compiler option '-std=c++11' when built against
libc++, such as is the case with Mac OS 10.9 or higher. However, by
default Slicer (and ITK) are not configured to use C++11. Thus when
SimpleITK is built against a non-'std=c++11' ITK build, there is a
mismatch between `VCL_CONSTEXPR` and the `VCL_CAN_STATIC_CONST_INIT_*`
preprocessor options, leading to compiler errors in Slicer and on the
SimpleITK dashboard [1,2]. Specifically, for '-std=c++11' compiler,

`VCL_CONSTEXPR = constexpr` as introduced in [3], but
`VCL_CAN_STATIC_CONST_INIT_{FLOAT,INT}` is undefined, leading to

`VCL_STATIC_CONST_INIT_FLOAT_DECL = ""`

leading to preprocessed definitions for VNL traits such as:

```
template <>
class vnl_numeric_traits<float>
...
static constexpr float zero ;
```

This causes the mentioned build errors because `constexpr` expressions
must be immediately constructible. The proposed patch unifies these
options so that they agree when VXL is compiled under '-std=c++11'.

[1] http://slicer-devel.65872.n3.nabble.com/build-error-in-simpleitk-td4035854.html
[2] https://open.cdash.org/buildSummary.php?buildid=4170100
[3] http://review.source.kitware.com/#/c/20386/

Change-Id: If04f4d3d0483fd8186e5a1189d183a9f0bb200d8
  • Loading branch information
ihnorton committed Jan 13, 2016
1 parent 6dec0b3 commit 0f748d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 0 additions & 10 deletions Modules/ThirdParty/VNL/src/vxl/core/vxl_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
# define VXL_BIG_ENDIAN @VXL_BIG_ENDIAN@
#endif

/* When using C++11 or greater, constexpr
* may be necessary for static const float initialization
* and is benificial in other cases where
* a value can be constant. */
#if __cplusplus >= 201103L
# define VCL_CONSTEXPR constexpr
#else
# define VCL_CONSTEXPR const
#endif

/* we can't just use typedefs, because on systems where there are */
/* no 64bit integers we have to #define vxl_int_64 to `void' in */
/* order to catch illegitimate uses. However, typedefs are superior */
Expand Down
12 changes: 12 additions & 0 deletions Modules/ThirdParty/VNL/src/vxl/vcl/vcl_config_compiler.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@
//----------------------------------------------------------------------
// constant initializer issues.

/* When using C++11 or greater, constexpr
* may be necessary for static const float initialization
* and is benificial in other cases where
* a value can be constant. */
#if __cplusplus >= 201103L
# define VCL_CONSTEXPR constexpr
# define VCL_CAN_STATIC_CONST_INIT_INT 1
# define VCL_CAN_STATIC_CONST_INIT_FLOAT 1
#else
# define VCL_CONSTEXPR const
#endif

//: VCL_STATIC_CONST_INIT_INT_DECL(x)
//
// ANSI allows
Expand Down

0 comments on commit 0f748d8

Please sign in to comment.