[Qt-creator] C++ parser and anonymous union, structs and classes

Alexander 'hatred' Drozdoff adrozdoff at gmail.com
Mon Dec 12 01:37:06 CET 2011


Hi guys!

I have structure in my project, that contain anonymous unions (also tried with structs and classes
- same result) and autocompletion for them look like incorrect. Example below:
~~~ cut here ~~~
#include <stdio.h>

struct st1 
{
  union
  {
    unsigned long ul;
    unsigned char raw[8];
  };

  // another fields...
};

struct st2
{
  union
  {
    unsigned long ul;
    unsigned char raw[8];
  } long_bytes;

  // another fields...
};


int main()
{
  struct st1 st1;
  struct st2 st2;

  // correct
  st1.ul            = 0xFFFEFDFC;
  // but:
  st2.long_bytes.ul = 0xFFFEFDFC;
  // and here error:
  ///st2.ul            = 0xFFFEFDFC;
  // but Qt Creator show 'ul' in auto-complete dialog for 'st2.'

  return 0;
}
~~~ cut here ~~~


in this example in structure 'st1' we can access to fields 'ul' and 'raw' directly - it valid, and
this fields displayed in autocompletion list - it valid. But, in structure 'st2' we can't access to
fields 'ul' and 'raw' directly (compiler exit with error) only via 'long_bytes' - it valid, but
autocomplete list shows all fields:
 ul
 raw
 long_bytes

it look like incorrect. I try to look in to code, but I don't understand it currently and can't
provide fix.

So, should I report issue, or it is 'feature'? :-)


Also, if I rewrite structure 'st2' as below (added type-name for union '__u1__'):
~~~ cut here ~~~
struct st2
{
  union __u1__
  {
    unsigned long ul;
    unsigned char raw[8];
  } long_bytes;

  // another fields...
};
~~~ cut here ~~~

Autocomplete list shows correctly, without 'ul' and 'raw' fields.

-- 
WBR
Alexander Drozdov
FIDO: 2:5045/41.84
Site: http://hatred.homelinux.net
Site: http://archlinux.org.ru



More information about the Qt-creator mailing list