Disallow built-in internal types to be inferred by auto#8510
Disallow built-in internal types to be inferred by auto#8510joaosaffran wants to merge 9 commits into
Conversation
tex3d
left a comment
There was a problem hiding this comment.
Some feedback in comments, plus, can you try to have something in one of the tests to tease out each of the interesting cases in IsTypeDeducibleWithAuto? For example, is there a non-deducible component type in vector/matrix (I don't think it's possible)? Or how about the string case? Also, what about arrays of deducible/non-deducible types? Plus, what code hits the pointer case?
If some of these are unreachable (like pointer), perhaps they should use llvm_unreachable instead.
| case AR_TOBJ_BASIC: | ||
| case AR_TOBJ_COMPOUND: | ||
| case AR_TOBJ_INTERFACE: | ||
| case AR_TOBJ_STRING: |
There was a problem hiding this comment.
I'm not sure STRING should be included here.
| // Container types: deducible iff their wrapped type is deducible. | ||
| case AR_TOBJ_MATRIX: | ||
| case AR_TOBJ_VECTOR: | ||
| return IsTypeDeducibleWithAuto(GetMatrixOrVectorElementType(type)); |
There was a problem hiding this comment.
I'm not sure why matrix/vector types aren't just always deducible. What element type is allowed with these types (we have separate checking for the allowed element template type) that would prevent this?
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
| if (IsSubobjectType(type)) | ||
| return false; | ||
|
|
||
| switch (GetTypeObjectKind(type)) { |
There was a problem hiding this comment.
I think the only two cases here that actually matter are AR_TOBJ_INNER_OBJ and AR_TOBJ_STRING right?
Any other case should result in an error from somewhere else in the compiler.
Why not just handle the string case and put an attribute on the inner object types that marks them as non-deducible?
If we also put that attribute implicitly on subobject types, we can flatten a lot of this to just a hasAttr check.
|
|
||
| // Matrices. | ||
| float2x2 matInit = { 1, 2, 3, 4 }; | ||
| auto m = matInit; |
There was a problem hiding this comment.
What about something like?
auto row = m[0];Co-authored-by: Chris B <beanz@abolishcrlf.org>
This patch adds the check into SemaDecl to disallow auto to infer built-in internal types, like
sample_typeandmip_type. And Subobject types, like the ones used in DXR.