CGF and initializers

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

CGF and initializers

Anders Carlsson
Hello,

I'm investigating a bug where -Wmissing-noreturn warns on any constructor with member or base initializers, for example:

int f();

struct A {
    int a;
    A() : a(f()) { }
};

The CFG for A::A() looks like:

 [ B2 (ENTRY) ]
    Predecessors (0):
    Successors (1): B1

 [ B1 ]
      1: f()
      2: a([B1.1]) (Member initializer)
    Predecessors (1): B2
    Successors (1): B0

 [ B0 (EXIT) ]
    Predecessors (1): B1
    Successors (0):

not sure about this, but wouldn't it make more sense for the member initializer to come before the call to f() ?

- Anders


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: CGF and initializers

Ted Kremenek
Hi Anders,

The value of f() is used for initializing the member, so there is a control-dependency between the call to f() and the member initializer, not the other way around.  The member is initialized after the call.

On Jan 11, 2011, at 9:58 AM, Anders Carlsson wrote:

> Hello,
>
> I'm investigating a bug where -Wmissing-noreturn warns on any constructor with member or base initializers, for example:
>
> int f();
>
> struct A {
>     int a;
>     A() : a(f()) { }
> };
>
> The CFG for A::A() looks like:
>
>  [ B2 (ENTRY) ]
>     Predecessors (0):
>     Successors (1): B1
>
>  [ B1 ]
>       1: f()
>       2: a([B1.1]) (Member initializer)
>     Predecessors (1): B2
>     Successors (1): B0
>
>  [ B0 (EXIT) ]
>     Predecessors (1): B1
>     Successors (0):
>
> not sure about this, but wouldn't it make more sense for the member initializer to come before the call to f() ?
>
> - Anders
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


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