Add null-type guards before QualType::getFromOpaquePtr#968
Conversation
|
I do not think this is a good change per se. In some cases if the input argument is nullptr it is unclear what is the right return value we should have. We can add non_null attributes to the function arguments but not early returns I guess. |
Two points: 1. This is the same pattern we currently have accross the code base (return a value that would fail a conditional e.g I think for the APIs touched in this PR it is trivial. |
That is one of the cases where returning is not the right answer. TCppType_t GetPointerType(TCppType_t type) {
INTEROP_TRACE(type);
if (!type)
return INTEROP_RETURN(nullptr);
QualType QT = QualType::getFromOpaquePtr(type);
return INTEROP_RETURN(getASTContext().getPointerType(QT).getAsOpaquePtr());
}Here the question is the type of a nullptr type is QualType that returns "isNull" or the equivalent nullptr_t? This is very hard to get it semantically right. We need to return std::optional or something else to express the intent you are trying to express. The interfaces should have been |
Some of these type-interfaces have missing null-guard, while others have them. In the ROOT-cppyy migration Ihit one such case with GetReferencedType. I took this opportunity to fond other places wehre this check would be good to have. Along with compiler-research/cppyy-backend#202, this enables 3 new root tests (
stl_vector_iadd,rdataframe_misc gh_20291anddistrdf-proxy columninfo)