Commit 043c229
Fix ambiguous operator<< overload with nullptr in DCHECK_NE
Summary:
Fix a compilation error when building fbcode//vllm:vllm.whl_py3.12 with opt mode.
The issue occurs because `DCHECK_NE(ptr, nullptr)` causes glog's
`MakeCheckOpString` template to be instantiated with `std::nullptr_t`,
which triggers an ambiguous overload resolution for `operator<<`.
Two candidates compete:
1. `std::ostream::operator<<(nullptr_t)` from the standard library
2. `operator<<` from `c10/util/logging_is_not_google_glog.h` (PyTorch)
The fix changes `DCHECK_NE(ptr, nullptr)` to `DCHECK(ptr != nullptr)`,
which avoids the template instantiation that formats nullptr for the
error message, while preserving the same runtime behavior.
Failure prior to this diff (https://www.internalfb.com/intern/test/281475244776612):
```
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:739:40: error: use of overloaded operator '<<' is ambiguous (with operand types 'basic_ostream<char, char_traits<char>>' and 'const std::nullptr_t')
739 | ss << names << " (" << v1 << " vs. " << v2 << ")";
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:765:1: note: in instantiation of function template specialization 'google::MakeCheckOpString<apache::thrift::util::TypeErasedValue<64> *, std::nullptr_t>' requested here
765 | DEFINE_CHECK_OP_IMPL(_NE, !=)
| ^
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:754:17: note: expanded from macro 'DEFINE_CHECK_OP_IMPL'
754 | else return MakeCheckOpString(v1, v2, names); \
| ^
buck-out/v2/gen/fbcode/thrift/lib/cpp2/server/__cpp2_conn_context__/e97a953a9065daad/buck-headers/thrift/lib/cpp2/server/Cpp2ConnContext.h:837:5: note: in instantiation of function template specialization 'google::Check_NEImpl<apache::thrift::util::TypeErasedValue<64> *, std::nullptr_t>' requested here
837 | DCHECK_NE(serviceInterceptorsStorage_.onRequest.get(), nullptr);
| ^
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:1092:5: note: expanded from macro 'DCHECK_NE'
1092 | CHECK_NE(val1, val2)
| ^
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:836:30: note: expanded from macro 'CHECK_NE'
836 | #define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
| ^
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:811:3: note: expanded from macro 'CHECK_OP'
811 | CHECK_OP_LOG(name, op, val1, val2, google::LogMessageFatal)
| ^
buck-out/v2/gen/fbcode/third-party-buck/platform010/build/glog/__glog__/f498b71eec7ffd5a/buck-headers/glog/logging.h:802:18: note: expanded from macro 'CHECK_OP_LOG'
802 | google::Check##name##Impl( \
| ^
<scratch space>:30:1: note: expanded from here
30 | Check_NEImpl
| ^
fbcode/third-party-buck/platform010/build/libgcc/include/c++/trunk/ostream:250:7: note: candidate function
250 | operator<<(nullptr_t)
| ^
buck-out/v2/gen/fbcode/conda/buck_integration/toolchains/third-party/___conda_fbpkg__/968469d7f0dafe3e/fbpkg/conda/lib/python3.12/site-packages/torch/include/c10/util/logging_is_not_google_glog.h:159:22: note: candidate function
159 | inline std::ostream& operator<<(
| ^
1 error generated.
```
Reviewed By: iahs, Mizuchi
Differential Revision: D89971848
fbshipit-source-id: ca0996e6c56bdb390dd950dc460b3d573884e8a61 parent c2a32fd commit 043c229
1 file changed
Lines changed: 1 addition & 1 deletion
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
837 | | - | |
| 837 | + | |
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
| |||
0 commit comments