Language
C++
Compiler
gcc 8.1.0
Options
Warnings
Boost 1.69.0
C++17
no pedantic
#include "variant.hpp"
#include <boost/variant.hpp>
#include <variant>
#include <cassert>
#include <iostream>
struct X {};
struct Guard
{
explicit Guard(int) {}
Guard(Guard&&) = delete;
};
int main()
{
{
using namespace std;
variant<X, Guard> v {};
v.emplace<Guard>(1);
}
{
using namespace boost::variant2;
variant<X, Guard> v {};
v.emplace<Guard>(1); // fails to compile because it requires moves
}
}
#ifndef BOOST_VARIANT2_VARIANT_HPP_INCLUDED
#define BOOST_VARIANT2_VARIANT_HPP_INCLUDED
// Copyright 2017-2019 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#if defined(_MSC_VER) && _MSC_VER < 1910
# pragma warning( push )
# pragma warning( disable: 4521 4522 ) // multiple copy operators
#endif
#ifndef BOOST_MP11_HPP_INCLUDED
#include <boost/mp11.hpp>
#endif
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <cstddef>
#include <type_traits>
#include <exception>
#include <cassert>
#include <initializer_list>
#include <utility>
//
namespace boost
{
namespace variant2
{
// bad_variant_access
$ g++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.69.0/gcc-8.1.0/include -std=c++17
Exit Code:
1