This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]