[LLVMbugs] [Bug 3272] New: scan-build barfs on C99 initialisers (except by chance).

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Dec 30 19:34:44 PST 2008


http://llvm.org/bugs/show_bug.cgi?id=3272

           Summary: scan-build barfs on C99 initialisers (except by chance).
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: parser
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nash at nash.id.au
                CC: llvmbugs at cs.uiuc.edu


Running scan-build -o . gcc -c -o struct.o struct.c

Gives the following messages: 
struct.c:19:9: warning: incompatible pointer to integer conversion initializing
'void (struct foo *)', expected 'int'
        .del = foodel,
               ^~~~~~
struct.c:20:10: warning: incompatible integer to pointer conversion
initializing 'int', expected 'int (*)(int)'
        .size = 92,
                ^~
struct.c:21:9: warning: incompatible pointer types initializing 'int (int)',
expected 'void (*)(struct foo *)'
        .add = fooadd,
               ^~~~~~
struct.c:19:9: error: initializer element is not a compile-time constant
        .del = foodel,
               ^~~~~~
4 diagnostics generated.


So the C99 initializers work fine if:
 - They are all there
 - They are in order.

Any missing or out of order initializers seems to mess everything up.
This is a really annoying bug as we make a lot of use of this style
initialisers so we can skip fields.

struct foo;

int fooadd(int x);
void foodel(struct foo *);

struct foo {
        int size;
        int (*add)(int fooinatate);
        void (*del)(struct foo *);
};

struct foo instance = {
        .size = 12,
        .add = fooadd,
        .del = foodel
};

struct foo instanceerr = {
        .del = foodel,
        .size = 92,
        .add = fooadd,
};


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list