On Fri, Dec 13, 2013 at 10:08 AM, Enrico Pertoso <[email protected]> wrote:
> http://llvm-reviews.chandlerc.com/D2387
[...]
> +void test_comma () {
> +  int a;  // expected-note {{initialize the variable 'a' to silence this 
> warning}}
> +  int b = (a, a ?: 2);  // expected-warning {{variable 'a' is uninitialized 
> when used here}}
> +  int c = (a, a, b, c);  // expected-warning {{variable 'c' is uninitialized 
> when used within its own initialization}}
> +  int d;  // expected-note {{initialize the variable 'd' to silence this 
> warning}}
> +  int e = (foo(d), e, b); // expected-warning {{variable 'd' is 
> uninitialized when used here}}
> +}

Incidentally, I don't see any test for the simple case of

    int g;
    int h = (g, 42);

where the uninitialized variable's first use is on the *left-hand*
side of a comma operator. (And where the uninitialized variable
doesn't have another unrelated use elsewhere on the same line, of
course.)  Nor

    int j, j2;
    int k = (j ?: 42);
    int k2 = (0 ?: j);

where the uninitialized variable's first use is on the LHS or RHS of a
?: operator.
Does this patch propose to warn in those cases (IMHO it should)? Is
there already a working test for those cases somewhere?

> +namespace mem_ptr {
> +struct A {
> +  int x;
> +  int y;
> +};
> +
> +void foo() {
> +  int A::* px = &A::x;
> +  A a{ 1, a.*px }; // expected-warning {{variable 'a' is uninitialized when 
> used within its own initialization}}

Notice that the same initializer should *not* warn if struct A is
defined as { int x; int& y; } (i.e., with member 'y' as a reference).
http://llvm.org/bugs/show_bug.cgi?id=14921 is vaguely related.

my $.02,
–Arthur

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to