Opened 6 years ago

#12595 new Bugs

Unexpected result when using type_erased adaptor to a transformed_range when clang optimizations are enabled

Reported by: Alfredo Altamirano <fredy.altamirano8@…> Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

If clang optimizations -O1 are enabled, when using type_erased adapter on a transformed_range, the range will yield wrong values.

For example:

int addOne(int b) {

return b + 1;

}

int main() {

std::vector<int> nums{ 1, 2, 3 }; auto result = nums | boost::adaptor::transformed(addOne) | boost::adaptor::type_erased<int, boost::forward_traversal_tag>();

}

When printing result, it yielded { 1, 1, 1 } instead of { 2, 3, 4 } when compiling with -O1. It worked as expected with no optimization flags. I am compiling the code with clang++. The version of clang is Apple LLVM version 8.0.0 (clang-800.0.38). And I am using c++11.

http://stackoverflow.com/questions/40479397/getting-unexpected-result-when-compiling-with-clang-optimization?noredirect=1#comment68203492_40479397

Attachments (1)

bug.cpp (692 bytes ) - added by Alfredo Altamirano <fredy.altamirano8@…> 6 years ago.
C++ code reproducing the code.

Download all attachments as: .zip

Change History (1)

by Alfredo Altamirano <fredy.altamirano8@…>, 6 years ago

Attachment: bug.cpp added

C++ code reproducing the code.

Note: See TracTickets for help on using tickets.