jeudi 24 septembre 2020

Missing missing return statement accepted by g++

class Foo
{
public:
    int bar()
    {
        bool bla = false;
        auto lambda = [&]() -> int {
            if (bla)
            {
                return 0;
            }
            // return 1;
        };
        (void)lambda;
        return 1;
    }
};

int main()
{
    Foo foo;
    foo.bar();
}

This example above perfectly compiles with g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0 and "-Wall -Wpedantic -Werror -Wextra".

However, e.g. https://cppinsights.io/ complains

/home/insights/insights.cpp:13:9: warning: non-void lambda does not return a value in all control paths [-Wreturn-type]
        };
        ^
1 warning generated.

Why does gcc not complain?

Aucun commentaire:

Enregistrer un commentaire