Subject: [Boost-bugs] [Boost C++ Libraries] #11251: boost::static_visitor<T&> causes a compilation error in C++14 mode
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-04-29 20:49:13
#11251: boost::static_visitor<T&> causes a compilation error in C++14 mode
----------------------------------------------+------------------------
Reporter: bogdan <inadgob@â¦> | Owner: ebf
Type: Bugs | Status: new
Milestone: To Be Determined | Component: variant
Version: Boost 1.58.0 | Severity: Regression
Keywords: variant visitor reference return |
----------------------------------------------+------------------------
Consider the following code:
{{{#!cpp
#include <iostream>
#include "boost/variant.hpp"
struct test_vis : boost::static_visitor<int&>
{
int& operator()(int& i) const { return i; }
};
int main()
{
boost::variant<int> dummy;
++boost::apply_visitor(test_vis(), dummy);
std::cout << dummy << '\n';
}
}}}
Clang 3.6.0 compiles the code with no diagnostics in C++11 mode, but in
C++14 mode it issues the following error:
{{{
prog.cc:12:6: error: call to 'apply_visitor' is ambiguous
++boost::apply_visitor(test_vis(), dummy);
^~~~~~~~~~~~~~~~~~~~
/boost/variant/detail/apply_visitor_unary.hpp:82:1: note: candidate
function [with Visitor = test_vis, Visitable = boost::variant<int>]
apply_visitor(const Visitor& visitor, Visitable& visitable)
^
/boost/variant/detail/apply_visitor_unary.hpp:160:23: note: candidate
function [with Visitor = test_vis, Visitable = boost::variant<int>]
inline decltype(auto) apply_visitor(const Visitor& visitor, Visitable&
visitable,
^
1 error generated.
}}}
The same behaviour occurs in GCC 5.1.0. MSVC12 compiles the code, MSVC14
issues a similar error.
This is due to the fact that the `apply_visitor` overloads using automatic
return type detection are not disabled in this case, because the
`boost::detail::variant::has_result_type` trait is not working properly
for reference types. Internally, it uses an overload with a parameter type
of `typename C::result_type*`, which tries to form a pointer to reference
type in this case, which causes a deduction failure.
A quick workaround is to remove the base class for the visitor in C++14
mode in this case.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11251> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC