[PATCH] D24110: [Sema] Don't diagnose an array type mismatch when the new or previous declaration has a dependent type
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 31 17:45:21 PDT 2016
ahatanak added inline comments.
================
Comment at: lib/Sema/SemaDecl.cpp:3377-3378
@@ -3376,4 +3376,4 @@
if (!Context.hasSameType(NewArray, PrevVDTy))
return diagnoseVarDeclTypeMismatch(*this, New, PrevVD);
}
----------------
rsmith wrote:
> ahatanak wrote:
> > rsmith wrote:
> > > If you do use `isDependentSizedArrayType()`, you'll need to change this to check the bounds of the array types rather than the type.
> > It seems to me that you don't want to do the check when either the array bound or the element type is dependent. Which case would we miss if isDependentType is used here instead of isDependentSizedArrayType? Could you show an example?
> Sure. We could diagnose both declarations in the template here:
>
> int a[5];
> int b[5];
> template<typename T, int N> void f() {
> extern T a[6];
> extern float b[N];
> }
>
> ... because in both cases the type can never match. However, we don't do this sort of partial type matching in any other cases, so it's very much just a "nice-to-have".
Ah, I see your point.
If we want to catch those cases too, perhaps we should define and use a function "hasDifferentType" which returns true only if the new and old arrays are known to have different types. In your example, the function would return true for "T a[6]" because we can see it will never match "int a[5]" regardless of what T is.
https://reviews.llvm.org/D24110
More information about the cfe-commits
mailing list