Subject: [Boost-bugs] [Boost C++ Libraries] #11285: Variant: apply_visitor broken with C ++14 and const references
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-05-11 19:56:54
#11285: Variant: apply_visitor broken with C ++14 and const references
------------------------------------+------------------------
Reporter: Roger Leigh <rleigh@â¦> | Owner: ebf
Type: Bugs | Status: new
Milestone: To Be Determined | Component: variant
Version: Boost 1.58.0 | Severity: Regression
Keywords: |
------------------------------------+------------------------
This is broken with C++14 with clang++, and Boost 1.58. It was working a
week back with Boost 1.57 prior to homebrew upgrading Boost to 1.58; I'll
double-check this wasn't due to XCode also being upgraded, though I don't
think that's a problem--I'd been using -std=c++14 routinely for some
months. Hence I've put this down as a regression, but there's a little
uncertainly there.
Sample minimal testcase:
{{{
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/variant.hpp>
#include <iostream>
#include <string>
struct a
{
const std::string& type() const
{
static const std::string v("a");
return v;
}
};
struct b
{
const std::string& type() const
{
static const std::string v("b");
return v;
}
};
typedef boost::variant<a,b> ab;
struct TestVisitor : public boost::static_visitor<const std::string&>
{
template <typename T>
const std::string&
operator() (const T& v)
{
return v.type();
}
};
int
main()
{
ab val = a();
TestVisitor v;
std::cout << boost::apply_visitor(v, val) << std::endl;
}
}}}
With clang++ on MacOS 10.10:
{{{
% clang++ --version
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
# Success for C++98:
% clang++ -o test test.cpp
% ./test
a
# Success for C++11
% clang++ -std=c++11 -o test test.cpp
% ./test
a
# Failure for C++14
% clang++ -std=c++14 -o test test.cpp
test.cpp:42:16: error: call to 'apply_visitor' is ambiguous
std::cout << boost::apply_visitor(v, val) << std::endl;
^~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/variant/detail/apply_visitor_unary.hpp:68:1:
note:
candidate function [with Visitor = TestVisitor, Visitable =
boost::variant<a,
b>]
apply_visitor(Visitor& visitor, Visitable& visitable)
^
/usr/local/include/boost/variant/detail/apply_visitor_unary.hpp:150:23:
note:
candidate function [with Visitor = TestVisitor, Visitable =
boost::variant<a,
b>]
inline decltype(auto) apply_visitor(Visitor& visitor, Visitable&
visitable,
^
/usr/local/include/boost/variant/detail/apply_visitor_unary.hpp:82:1:
note:
candidate function [with Visitor = TestVisitor, Visitable =
boost::variant<a,
b>]
apply_visitor(const Visitor& visitor, Visitable& visitable)
^
/usr/local/include/boost/variant/detail/apply_visitor_unary.hpp:160:23:
note:
candidate function [with Visitor = TestVisitor, Visitable =
boost::variant<a,
b>]
inline decltype(auto) apply_visitor(const Visitor& visitor, Visitable&
visitable,
^
1 error generated.
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11285> 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