Bug #47011 Declaring variables multiple times in for-loops break with some compilers
Submitted: 31 Aug 2009 10:21 Modified: 17 Jan 2014 12:15
Reporter: Geert Vanderkelen Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:mysql-5.1 OS:HP/UX (11.23 ia64)
Assigned to: CPU Architecture:Any
Tags: compiling

[31 Aug 2009 10:21] Geert Vanderkelen
Description:
I was/am trying to compile 32-bit MySQL binaries on HP-UX 11.23 ia63. At one point it was compiling sql/log_event.cc but error'ed saying the variable i was already declared in following code:

sql/log_event.cc

Format_description_log_event(const char* buf,
                             uint event_len,
                             const
                             Format_description_log_event*
                             description_event)
..
    for (int i= 1; i < 23; i++)
      post_header_len_temp[perm[i] - 1]= post_header_len[i - 1];
    for (int i= 0; i < 22; i++)
      post_header_len[i] = post_header_len_temp[i];

How to repeat:
Take source 5.1.37 and configure it like this on HP-UX 11.23 ia64:

CC=cc CFLAGS="+DD32 +DSitanium2 -mt -DHPUX11  -DSNPRINTF_RETURN_TRUNC -DHAVE_BROKEN_PREAD -DHAVE_BROKEN_GETPASS -DNO_FCNTL_NONBLOCK -DDO_NOT_REMOVE_THREAD_WRAPPERS -DHAVE_BROKEN_PTHREAD_COND_TIMEDWAIT -DHAVE_BROKEN_INLINE -DUNIV_HPUX" CXX=aCC CXXFLAGS="+DD32 +DSitanium2 -mt -DHPUX11  -DSNPRINTF_RETURN_TRUNC -DHAVE_BROKEN_PREAD -DHAVE_BROKEN_GETPASS -DNO_FCNTL_NONBLOCK -DDO_NOT_REMOVE_THREAD_WRAPPERS -DHAVE_BROKEN_PTHREAD_COND_TIMEDWAIT -DHAVE_BROKEN_INLINE -DUNIV_HPUX" ./configure --prefix="/somewhere/mysql-5.1.37-hpux32"

(Not sure if all the options are needed..)

Suggested fix:
Clean it up:

  int i;
  ..
  for (i= 1; i < 23; i++)
      post_header_len_temp[perm[i] - 1]= post_header_len[i - 1];
  for (i= 0; i < 22; i++)
      post_header_len[i] = post_header_len_temp[i];

Or just stick with forgiving compilers as workaround? :-)
[31 Aug 2009 10:36] Geert Vanderkelen
Compiler used:
cc: HP aC++/ANSI C B3910B A.06.01 [Jan 05 2005]

Setting to verified.
It's more a 'coding style' problem in the end..
[31 Aug 2009 10:38] Geert Vanderkelen
Next error:

sql/sql_prepare.cc 

void reinit_stmt_before_use(THD *thd, LEX *lex)
..
  for (TABLE_LIST *tables= lex->query_tables;
       tables;
       tables= tables->next_global)
  ..
  for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxiliary_table_list.first;
       tables;
       tables= tables->next_global)
[31 Aug 2009 11:55] Geert Vanderkelen
"commands.cc", line 1416: error #2101: "i" has already been declared in the
          current scope
    for (uint i= 0; i < instance_options_map.records; ++i)
[17 Jan 2014 12:15] Ståle Deraas
Posted by developer:
 
The proper status is not a bug, since this is legal C++