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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to