Opened 9 years ago
Last modified 6 years ago
#8712 new Bugs
[function] Comparison with nullptr differs from std::function<>
Reported by: | Owned by: | Douglas Gregor | |
---|---|---|---|
Milestone: | To Be Determined | Component: | function |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | nullptr C++11 | Cc: |
Description
Whether or not boost::function<> should support comparison with (C++11) nullptr is another issue, but at the moment it is inconsistent with std::function<>.
E.g.
boost::function<void ()> bf; bool c1 = (bf == nullptr); // currently false std::function<void ()> sf; bool c2 = (sf == nullptr); // true assert(c1 == c2);
Tested with g++ 4.6.3 and Visual Studio 2012.
Change History (2)
comment:1 by , 9 years ago
comment:2 by , 6 years ago
Just encountered this in our code base. We ran clang-tidy with modernize-use-nullptr which converted some code from:
if (aBoostFunction == NULL) { ... } else { aBoostFunction(...); }
to:
if (aBoostFunction == nullptr) { ... } else { aBoostFunction(...); }
This change caused the comparison to return false as shown above and the empty function was invoked.
Note:
See TracTickets
for help on using tickets.
I add a major hit count for this to be fixed!