LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 42604 - -Wuninitialized for struct assignment from GNU C statement expression
Summary: -Wuninitialized for struct assignment from GNU C statement expression
Status: RESOLVED DUPLICATE of bug 31829
Alias: None
Product: clang
Classification: Unclassified
Component: C (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Nathan Huckleberry
URL: https://github.com/ClangBuiltLinux/li...
Keywords:
Depends on:
Blocks: 31829
  Show dependency tree
 
Reported: 2019-07-12 09:37 PDT by Nick Desaulniers
Modified: 2019-07-18 15:08 PDT (History)
10 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Desaulniers 2019-07-12 09:37:05 PDT
Consider the following example:

void init(int*);

void foo(void) {
    int i = ({
        init(&i);
        i;
    });
}

struct widget {
    int x, y;
};
void init2(struct widget*);

void bar(void) {
    struct widget my_widget = ({
        init2(&my_widget);
        my_widget;
    });
}

warning: variable 'my_widget' is uninitialized when used within its own initialization [-Wuninitialized]

It seems like it's ok to do so for non-aggregate types, but aggregates issue the warning.  I think it should not be a warning here?
Comment 1 sguelton 2019-07-17 06:46:52 PDT
Same error, without GCC extension:

```c

struct widget {
    int x, y;
};
void init2(struct widget*);

void bar(void) {
    struct widget my_widget = (init2(&my_widget), my_widget);
}
```
Comment 2 Richard Smith 2019-07-17 07:53:31 PDT
These examples are undefined in C++, but valid in C; we should probably just disable this warning in C. (Without doing a significantly more sophisticated analysis, it's going to be hard to get it right.)
Comment 3 Nick Desaulniers 2019-07-18 14:11:54 PDT
WIP: https://reviews.llvm.org/D64678
Comment 4 Nick Desaulniers 2019-07-18 15:08:20 PDT

*** This bug has been marked as a duplicate of bug 31829 ***