[LLVMbugs] [Bug 12058] New: std::shared_ptr's op bool is not explicit

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Feb 21 12:48:03 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=12058

             Bug #: 12058
           Summary: std::shared_ptr's op bool is not explicit
           Product: libc++
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: dblaikie at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


std::shared_ptr's operator bool is not marked 'explicit'. This leads to some
somewhat dangerous/surprising code (as any op bool does):

#include <memory>
int main() {
  std::shared_ptr<int> sp;
  sp == NULL;
}

This case happens to actually do the right thing (I think... - sp converts to
boolean (false, in this case) false/0 compared with NULL/0 is equal) but many
other cases won't be so kind. ( http://www.artima.com/cppsource/safebool.html
is a nice article on the issues & workarounds in C++03)

If libc++ is going to provide this for backwards compatibility, it'd be really
nice if it did it in a safer way (at least as safe as iostreams op void*, if
not safer (article above works through the various issues & solutions)) & it'd
certainly be best if libc++ used the real language feature (explicit
conversions) where available.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list