https://bugs.llvm.org/show_bug.cgi?id=41274

            Bug ID: 41274
           Summary: _LIBCPP_DEBUG=1 std::transform in-place: abort()
                    (Attempted to dereference a non-dereferenceable
                    iterator)
           Product: libc++
           Version: 8.0
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

When using std::transform on a copy-initialized std::string to transform it
in-place, compiling the program with -D_LIBCPP_DEBUG=1 makes the iterator
checks at runtime fail. When compiling without the debug flag, the program
works both optimized and unoptimized as expected. I'm using the LLVM 8.0.0
release build on macOS, installed to /usr/local/opt/llvm.


Example program:

#include <algorithm>
#include <iostream>

int main(int argc, char *argv[]) {
    std::string source = "hello";

    std::string the_copy = source;

    std::transform(source.begin(), source.end(), source.begin(), [](unsigned
char c) -> unsigned char {
        return std::toupper(c);
    });

    std::cout << "transformed source: " << source << "\n\n";

    std::transform(the_copy.begin(), the_copy.end(), the_copy.begin(),
[](unsigned char c) -> unsigned char {
        return std::toupper(c);
    });

    std::cout << "transformed copy: " << the_copy << "\n\n";
}


Compile command:

/usr/local/opt/llvm/bin/clang++ main.cpp -o main -D_LIBCPP_DEBUG=1 -g -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
/usr/local/opt/llvm/lib/libc++.a -lc++abi -nodefaultlibs -lSystem -std=c++17


Output:

transformed source: HELLO

/usr/local/opt/llvm/bin/../include/c++/v1/iterator:1372: _LIBCPP_ASSERT
'__get_const_db()->__dereferenceable(this)' failed. Attempted to dereference a
non-dereferenceable iterator
[1]    32560 abort      ./main

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to