This is an archive of the discontinued LLVM Phabricator instance.

Make -Wgcc-compat complain about declarations in for loop init statements
ClosedPublic

Authored by george.burgess.iv on Jun 6 2018, 11:58 AM.

Details

Summary

The following code is invalid before C99, since we try to declare i inside the first clause of the for loop:

void foo() {
  for (int i = 0; i < 10; i++);
}

GCC does not accept this code in c89 or gnu89, but clang does: https://godbolt.org/g/ZWr3nA .

If the user cares about GCC compatibility, we should probably warn about this if we're not in C99.

I'm not 100% thrilled that we're emitting two warnings about the same thing for slightly different reasons; alternatives welcome. :)

Diff Detail

Event Timeline

rsmith accepted this revision.Jun 28 2018, 2:13 PM

I'm not 100% thrilled that we're emitting two warnings about the same thing for slightly different reasons; alternatives welcome. :)

Me either, but given our policy that warning flags just filter out warnings, I'm not sure what other options we have.

This revision is now accepted and ready to land.Jun 28 2018, 2:13 PM
This revision was automatically updated to reflect the committed changes.