This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't diagnose an array type mismatch when the new or previous declaration has a dependent type
ClosedPublic

Authored by ahatanak on Aug 31 2016, 4:50 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak updated this revision to Diff 69927.Aug 31 2016, 4:50 PM
ahatanak retitled this revision from to [Sema] Don't diagnose an array type mismatch when the new or previous declaration has a dependent type.
ahatanak updated this object.
ahatanak added reviewers: v.g.vassilev, rsmith.
ahatanak added a subscriber: cfe-commits.
rsmith added inline comments.Aug 31 2016, 4:59 PM
lib/Sema/SemaDecl.cpp
3370–3374 ↗(On Diff #69927)

Maybe use isDependentSizedArrayType() here instead, so we still diagnose cases where the element type is dependent but the array bound is non-dependent and differs.

rsmith accepted this revision.Aug 31 2016, 5:01 PM
rsmith edited edge metadata.

LGTM as-is, but one suggestion if you want to still allow diagnosing a few more cases.

lib/Sema/SemaDecl.cpp
3377–3378 ↗(On Diff #69927)

If you do use isDependentSizedArrayType(), you'll need to change this to check the bounds of the array types rather than the type.

This revision is now accepted and ready to land.Aug 31 2016, 5:01 PM
ahatanak added inline comments.Aug 31 2016, 5:21 PM
lib/Sema/SemaDecl.cpp
3377–3378 ↗(On Diff #69927)

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?

rsmith added inline comments.Aug 31 2016, 5:30 PM
lib/Sema/SemaDecl.cpp
3377–3378 ↗(On Diff #69927)

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".

ahatanak added inline comments.Aug 31 2016, 5:45 PM
lib/Sema/SemaDecl.cpp
3377–3378 ↗(On Diff #69927)

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.

I'll commit the patch as-is first and come up with a new patch which implements the improvements you suggested later.

This revision was automatically updated to reflect the committed changes.