#Usage of non-initialized field '_bar'

5 messages · Page 1 of 1 (latest)

summer iron
#

I've been trying to figure out why my inspector tells me "Usage of non-initialized field '_bar' when called from function 'create'" . I use a factory pattern a lot in my current project and never had this issue pop up and so I am confused if the inspector (which to my knowledge never reported false warnings so far) is wrong or am I not seeing an issue here?

Was able to reduce the issue down to this example:

struct Bar {};

class Foo
{
public:
    static auto create(Bar bar) -> Foo
    {
        return Foo { bar };
    }

private:
    Bar _bar; // Usage of non-initialized field '_bar' when called from function 'create'

    explicit Foo(Bar bar) : _bar(bar) {}
};

update: adding a custom move constructor removes the warning. Now I am even more confused

shy gardenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

sullen phoenix
#

If this is your exact code, looks like a false positive

summer iron
#

aight thanks

#

!solved