#include <boost/range/sub_range.hpp> #include <string> #include <vector>
using srange = boost::sub_range<std::string const>; void func(srange) // by value {} int main() { std::string kitty{"meow"}; srange hello{kitty}; srange const& helref = hello; func(hello); func(helref); // line 17 return 0; } $ g++ -v gcc version 9.0.0 20180626 (experimental) (GCC) $ g++ -Wall -pedantic -Wextra -Werror -save-temps subra.cpp subra.cpp: In function ‘int main()’: subra.cpp:17:13: error: implicitly-declared ‘constexpr boost::sub_range<const std::__cxx11::basic_string<char> >::sub_range(const boost::sub_range<const std::__cxx11::basic_string<char> >&)’ is deprecated [-Werror=deprecated-copy] func(helref); ^ In file included from subra.cpp:1: /usr/include/boost/range/sub_range.hpp:259:20: note: because ‘boost::sub_range<const std::__cxx11::basic_string<char> >’ has user-provided ‘boost::sub_range<ForwardRange>& boost::sub_range<ForwardRange>::operator=(const boost::sub_range<ForwardRange>&) [with ForwardRange = const std::__cxx11::basic_string<char>]’ sub_range& operator=( const sub_range& r ) ^~~~~~~~ subra.cpp:7:6: note: initializing argument 1 of ‘void func(srange)’ void func(srange) // by value ^~~~ I have two questions: 1. Why is a warning emitted only for the const srange? 2. Shouldn't boost be exempt from this warning, given that it's included from a system directory (/usr/include) ? Shouldn't the "implicitly declared copy constructor" error be located at the class definition (boost header), rather than where it's being called (the call which does pass-by-value) ? Boost is version 1.62.0.1 packaged by Ubuntu 17.10, so I can't change that. Csaba Please CC me, I'm not subscribed to the list. -- You can get very substantial performance improvements by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler So if you're looking for a completely portable, 100% standards-conformat way to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)