This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/70910] error declaring a type in clause-1 of a for statement


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70910

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks for the pointer.  That seems like a rather gratuitous restriction, and
an unnecessary deviation from the C++ rule where the feature originated.  I'm
also not sure that the committee's response to the DR is a fully informed one:
the claim that the intent can clearly be derived from the requirement that "a
for statement shall only declare identifiers for objects having storage class
auto or register" doesn't sound right to me.  I would expect the intent of the
requirement to be to prohibit defining loop control variables that are static
(and then have some such loops iterate only in the first invocation of the
function and not subsequent ones (*)).  I'll have to see if I can dig up some
background on the intent in the committee reflector archives or meeting
minutes.

But given that it's explicitly disallowed, I think it's unfortunate that GCC
doesn't accept the test case as an extension because other popular compilers
do, including the latest EDG 3.10 in strict conformance mode, Oracle c99, and
IBM xlc (though the last one rejects the struct definition).  With some more
testing, I see that Clang 3.8 rejects it.  Intel icc rejects it because it uses
the EDG front end in GCC compatibility mode (where the latter rejects it for
compatibility with GCC).

[*] As in the following also apparently valid C++ program:

void f ()
{
  for (static int i = 0; i < 10; ++i)
    printf ("%i\n", i);
}

int main ()
{
  f ();
  f ();
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]