Skip to content

#1726 Do not use std::complex<ft> unless ft is float/double/long double in tests

Metadata

Property Value
Reported by Elias Pipping (elias.pipping@fu-berlin.de)
Reported at Oct 25, 2015 08:05
Type Bug Report
Version Git (pre3.0)
Operating System Unspecified / All

Description

I'm on a machine with the system compiler

gcc (Debian 4.9.2-10) 4.9.2

on which I use

clang version 3.7.0 (tags/RELEASE_370/final)

that I compiled myself and which uses the libstdc++ provided by the aforementioned gcc.

Dune determines that this compiler supports C++14/C++1y because the snippet

  #include <memory>
 
  int main() {
    std::make_unique<int>();
  }

from cmake/modules/CheckCXXFeatures.cmake compiles. In fact, not all is well, though: If you take the piece of code

  #include <complex>

  int
  main()
  {
    std::complex<int> const x(1,2);
    int r = x.real();
  }

this compiles with 'clang++ -std=c++11' but not with 'clang++ -std=c++14'. In the latter case, I get the error

  foo.cc:7:13: error: no matching member function for call to 'real'
  int r = x.real();
          ~~^~~~
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/complex:144:7: note: 
      candidate function not viable: 'this' argument has type 'const std::complex<int>',
      but method is not marked const
      real() { return _M_real; }
      ^

The relevant lines here are:

   143	      constexpr _Tp 
   144	      real() { return _M_real; }

I came across this problem because it makes dune-common's fvectortest fail in the same way here:

dune/common/densevector.hh:77:16: error: no matching
      member function for call to 'real'
      return c.real()*c.real() + c.imag()*c.imag();

I can think of at least two ways to address this:

  • catch this issue in dune-common's C++1y feature check. The patch I've attached does the trick (maybe there's a nicer way to split this check into two separate memory/complex checks and maybe there's a way to avoid the code duplication, too).
  • Allow the user to selectively disable C++14 or C++1y (yet keep using C++11). Currently, I only see a way to disable all checks for C++ features; because dune relies on C++11, the check for which is disabled, too, though, that doesn't seem very useful.

Attachments