[Bug c++/86495] New: false no return statement warning in "if constexpr" branch

tower120 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jul 11 17:55:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86495

            Bug ID: 86495
           Summary: false no return statement warning in "if constexpr"
                    branch
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tower120 at gmail dot com
  Target Milestone: ---

The following code produce false "no return statement" warning in gcc 8.1.
Everything fine on 7.x

Live: https://godbolt.org/g/dCuFci

#include <iostream>
#include <variant>

template<class Base, class Variant>
class variant_w_base{
    Base* m_base;
    Variant m_variant;

    void update_base(){
        m_base = std::visit([](auto&& arg) -> Base* {
            using Arg = std::decay_t<decltype(arg)>;
            // ERRONEOUS WARNING HERE.
            if constexpr (std::is_same_v<Arg, std::monostate>){
                return nullptr;
            } else {
                return static_cast<Base*>(&arg);
            }
        }, m_variant);
    }

public:
    variant_w_base(){
        update_base();
    }
};


int main() {
    struct Base{};
    struct Data : Base{};
    variant_w_base<Base, std::variant<Data>> v;

    return 0;
}


More information about the Gcc-bugs mailing list