Opened 8 years ago

Last modified 8 years ago

#10430 assigned Bugs

joined_range generates invalid range with recent gcc versions with optimization enabled

Reported by: Oliver Seiler <oseiler@…> Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

This came up in tracking down unit-test failures when trying to build a project with newer compiler versions with C++11 enabled. The unit-test in question was compiled with multiple compiler versions:

  • gcc 4.3.4 (without C++11 enabled): working at all optimization levels
  • gcc 4.7.2 (with C++11 enabled): works without optimizations, failed with -O1 or higher
  • gcc 4.8.4 (with C++11 enabled): works without optimizations, failed with -O1 or higher
  • clang 3.5.0 (recent build, with C++11 enabled): works at all optimization levels

The failure was tracked down to a use of boost::range::joined_range (Boost 1.55.0), effectively declared as:

boost::range::joined_range<boost::iterator_range<std::vector<char>::iterator, boost::iterator_range<const char*>>

In this form, the joined_range created from two valid ranges winds up "somewhere else" when the higher optimization level. I've attached a test case that demonstrates the problem. Compiled with:

g++ -std=c++11 -o join_bug join_bug.cpp

works (printing out the expected ASCII values of the joined ranges). Compiled with:

g++ -O1 -std=c++11 -o join_bug join_bug.cpp

fails (printing out zero's in my test, though the correct number of them). This test was run with the same compiler versions as above, on both Boost 1.54.0 and Boost 1.55.0, as well as gcc 4.8.2 and clang 3.4 (both for Ubuntu 14.04), with a slightly modified non-C++11 version for the gcc 4.3.4 compiler, all with the same successes/failures.

The problem goes away in all tests if the joined_range is declared like so (changing from std::vector<char>::iterator to std::vector<char>::const_iterator):

boost::range::joined_range<boost::iterator_range<std::vector<char>::const_iterator, boost::iterator_range<const char*>>

I realize this might be a gcc bug, rather than a Boost bug, but I haven't seen this reported elsewhere and would like to get the behaviour tracked since I'm only seeing problems in relation to joined_range...

Attachments (1)

join_bug.cpp (760 bytes ) - added by Oliver Seiler <oseiler@…> 8 years ago.

Download all attachments as: .zip

Change History (2)

by Oliver Seiler <oseiler@…>, 8 years ago

Attachment: join_bug.cpp added

comment:1 by Neil Groves, 8 years ago

Status: newassigned
Note: See TracTickets for help on using tickets.