jimporter / mettle

A C++20 unit test framework
https://jimporter.github.io/mettle
BSD 3-Clause "New" or "Revised" License
122 stars 12 forks source link

Some tests are broken on GCC 5.3 #22

Closed snizovtsev closed 8 years ago

snizovtsev commented 8 years ago

Here is the output https://gist.github.com/snizovtsev/291238175c364a231026e0508fb3cc2c

jimporter commented 8 years ago

What's the exact GCC version you're on? I'm on the following and all tests pass:

g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204
snizovtsev commented 8 years ago

I'm using Nix [1] package manager with gcc5 from nixpkgs-stable:

$ g++ --version
g++ (GCC) 5.3.0

[1] https://nixos.org/nix/

jimporter commented 8 years ago

Hmm. What are the flags you set for GCC? For my build, CXXFLAGS="-Wall -Wextra -pedantic" and that's it.

snizovtsev commented 8 years ago

Nothing:

# ...
    patchPhase = ''
      cp -a ${bencode}/include/bencode.hpp include
    '';
    configurePhase = ''
      export INSTALL=install
      export BOOST_INCLUDEDIR=${pkgs.boost.dev}/include
      export BOOST_LIBRARYDIR=${pkgs.boost.lib}/lib
      bfg9000 --prefix $prefix . build
    '';
    buildPhase = ''
      ninja -C build -j $NIX_BUILD_CORES
    '';
    checkPhase = ''
      ninja -C build -j $NIX_BUILD_CORES test
    '';
    installPhase = ''
      ninja -C build install
    '';
# ...
jimporter commented 8 years ago

Weird. So the issue is that stringification of the type name via mettle::type_name<T>() isn't working right. Could you try compiling and running the following? It's probably going to print something different from what I expect:

#include <iostream>

namespace mettle {
  template<typename T>
  std::basic_string<char> type_name() {
    return std::string(__PRETTY_FUNCTION__);
  }
}

int main() {
  std::cout << mettle::type_name<int>() << std::endl;
  return 0;
}

Here's what I get: std::basic_string<char> mettle::type_name() [with T = int]

snizovtsev commented 8 years ago

Here is my output under Ubuntu 15.10 with installed Nix:

$ nix-shell -p gcc5 --pure

[nix-shell:~]$ c++ -std=c++14 test.cc

[nix-shell:~]$ ./a.out
std::__cxx11::basic_string<char> mettle::type_name() [with T = int]
snizovtsev commented 8 years ago

Here is part of default.nix file for nix-shell that builds mettle as dependency of our project: https://gist.github.com/snizovtsev/3fbd3017cc4315b6fe4eabb3a66224f9

jimporter commented 8 years ago

Ok, so it's actually an issue with libstdc++; they added an inline namespace at some point like libc++ has. I might end up having to use a regex instead of assuming I know what __PRETTY_FUNCTION__ looks like.

jimporter commented 8 years ago

Could you try with the gcc-dual-abi branch I just pushed? It should resolve the issue.

snizovtsev commented 8 years ago

It works: i've tested it under Nix/Clang 3.7.1 libc++/Darwin and Nix/GCC 5.3 stdc++/Ubuntu. Thank you!

jimporter commented 8 years ago

This is in the master branch now. Thanks for the bug report!