clang + boost regex + xenial = linker error

Bug #1664321 reported by nils mccarthy
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
llvm-toolchain-3.8 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I get a linker error compiling the following with clang++-3.8 optimization level -O1:

#include <boost/regex.hpp>

int main() {
  boost::regex re;
  std::string str;
  boost::smatch match;
  boost::regex_match(str, match, re);

  return 0;
}

It works fine with gcc:

$ g++ -O1 -o boost-clang-bug.gcc boost-clang-bug.cpp -lboost_regex

Or with clang -O0:

$ clang++-3.8 -O0 -o boost-clang-bug.o0 boost-clang-bug.cpp -lboost_regex

But not with clang -O1:

$ clang++-3.8 -O1 -o boost-clang-bug.o1 boost-clang-bug.cpp -lboost_regex
/tmp/boost-clang-bug-64dd61.o: In function `boost::cpp_regex_traits<char>::transform[abi:cxx11](char const*, char const*) const':
boost-clang-bug.cpp:(.text._ZNK5boost16cpp_regex_traitsIcE9transformB5cxx11EPKcS3_[_ZNK5boost16cpp_regex_traitsIcE9transformB5cxx11EPKcS3_]+0x23): undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform[abi:cxx11](char const*, char const*) const'
/tmp/boost-clang-bug-64dd61.o: In function `boost::cpp_regex_traits<char>::transform_primary[abi:cxx11](char const*, char const*) const':
boost-clang-bug.cpp:(.text._ZNK5boost16cpp_regex_traitsIcE17transform_primaryB5cxx11EPKcS3_[_ZNK5boost16cpp_regex_traitsIcE17transform_primaryB5cxx11EPKcS3_]+0x23): undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary[abi:cxx11](char const*, char const*) const'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Instead of giving an error, I would expect clang to successfully compile and link this program.

I'm using a stock install of xenial (on AWS, ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170113 (ami-7c803d1c)) updating and installing these:

$ sudo apt-get update
$ sudo apt-get install clang-3.8 libboost-regex1.58 g++

Here's relevant versioning information:

$ lsb_release -rd
Description: Ubuntu 16.04.1 LTS
Release: 16.04
$ apt-cache policy clang-3.8
clang-3.8:
  Installed: 1:3.8-2ubuntu4
  Candidate: 1:3.8-2ubuntu4
  Version table:
 *** 1:3.8-2ubuntu4 500
        500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages
        100 /var/lib/dpkg/status
     1:3.8-2ubuntu1 500
        500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in llvm-toolchain-3.8 (Ubuntu):
status: New → Confirmed
Revision history for this message
Henning Meyer (henning.meyer) wrote :

I get the same error when compiling on 16.04, it links fine on 16.10

I suspect that might be because gcc6 of 16.10 defaults to C++14 when the boost regex libraries were built, but have not verified that

Revision history for this message
Henning Meyer (henning.meyer) wrote :

I believe this is a related bug report in debian
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=823978

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.