Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-04-05 18:17:38


The code below works as expected when compiled with g++ 3.4 as:

$ g++ -I$HOME/boost/cvs -g -W -Wall -o static_test2 static_test2.cpp

but it also produces this warning:

static_test2.cpp: In static member function `static foo foo::set()':
static_test2.cpp:15: warning: no return statement in function returning
non-void

Clearly, I could add a spurious return statement after the assert, but
isn't g++ being a little over eager here? Can the warning not be silenced
by the library?

Regards,
Angus

#include <boost/static_assert.hpp>
#include <iostream>

class foo {
public:
    enum state {
        state1,
        state2,
        state3
    };

    // Only the specializations (below) of this template will compile.
    template <int N>
    static foo
    set() { BOOST_STATIC_ASSERT( N == state2 ); }

private:
    foo(state)
    {
        std::cout << "foo" << std::endl;
    }
};

template <>
foo foo::set<foo::state2>() { return foo::state2; }

template <>
foo foo::set<foo::state3>() { return foo::state3; }

int main()
{
    // Compiles, as expected.
    foo f1 = foo::set<foo::state2>();
    foo f2(foo::set<foo::state2>());
    // Fail to compile, as expected.
// foo f3 = foo::set<foo::state1>();
// foo f4(foo::set<foo::state1>());

    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk