Declaring a delegation method as constexpr when the called function is specified using constexpr

Please consider the following class

template<class T>
class foo
{
public:
    auto bar() { return m_t.bar(); }

private:
    T m_t;
};

If we want foo<T>::barnot to metal, when T::barnot to metal, we can change his declaration to

auto bar() noexcept(noexcept(m_t.bar())) { return m_t.bar(); }

But what can we do if we want to be foo<T>::barindicated with constexprwhen T::bargiven with constexpr?

Can we write

constexpr auto bar() noexcept(noexcept(m_t.bar())) { return m_t.bar(); }

and will it work anyway? I tested this with clang 3.7 (C ++ 17) and it seems to be so, but I'm not sure if the compiler works correctly here.

+4
source share
1 answer

[dcl.constexpr]:

constexpr - constexpr constexpr, - constexpr constexpr, . constexpr constexpr , ; .

, T, constexpr X bar(), , . T constexpr bar(), foo::bar - constexpr, .

+5

All Articles