[cfe-dev] clang and a class with non-copyable and non-assignable member

Edward Diener eldlistmailingz at tropicsoft.com
Sat Jan 17 10:59:04 PST 2015


On 1/17/2015 11:53 AM, David Blaikie wrote:
> Do you have a complete (standalone - preprocessed) example of this behavior?

Currently it come from trying to build Boost.Test on Windows using clang 
for Windows built for mingw/gcc-4.8.1.

There is an execution_monitor class in execution_monitor.hpp which has 
as a member:

boost::scoped_ptr<detail::translate_exception_base> m_custom_translators;

The detail::translate_exception_base class, which is an abstract class, 
itself has as a member:

boost::scoped_ptr<translate_exception_base> m_next;

boost::scoped_ptr is the inspiration for std::unique_ptr and is 
non-copyable, non-asignable. An execution_monitor instance is never 
copied or assigned.

Building Boost.Test with clang gives errors:

-------------------------------------------------

"..\..\..\boost/test/execution_monitor.hpp:59:23: error: 'operator=' is 
a private member of 
'boost::scoped_ptr<boost::detail::translate_exception_base>'
class BOOST_TEST_DECL translate_exception_base {
                       ^
..\..\..\boost/smart_ptr/scoped_ptr.hpp:48:18: note: declared private here
     scoped_ptr & operator=(scoped_ptr const &);
                  ^
..\..\..\boost/test/execution_monitor.hpp:59:23: note: implicit copy 
assignment operator for 'boost::detail::translate_exception_base' first 
required here
class BOOST_TEST_DECL translate_exception_base {
                       ^
..\..\..\boost/test/execution_monitor.hpp:59:23: error: field of type 
'boost::scoped_ptr<translate_exception_base>' has private copy constructor
class BOOST_TEST_DECL translate_exception_base {
                       ^
..\..\..\boost/smart_ptr/scoped_ptr.hpp:47:5: note: declared private here
     scoped_ptr(scoped_ptr const &);
     ^
..\..\..\boost/test/execution_monitor.hpp:59:23: note: implicit copy 
constructor for 'boost::detail::translate_exception_base' first required 
here
class BOOST_TEST_DECL translate_exception_base {
                       ^
..\..\..\boost/test/execution_monitor.hpp:143:23: error: field of type 
'boost::scoped_ptr<detail::translate_exception_base>' has private copy 
constructor
class BOOST_TEST_DECL execution_monitor {
                       ^
..\..\..\boost/smart_ptr/scoped_ptr.hpp:47:5: note: declared private here
     scoped_ptr(scoped_ptr const &);
     ^"

----------------------------------------------

Gcc 4.8.1, which is used to build clang has no problem with any of this.

I can try to work up as simple a standalone example as possible which 
will replicate this behavior.

>
> On Sat, Jan 17, 2015 at 8:06 AM, Edward Diener
> <eldlistmailingz at tropicsoft.com
> <mailto:eldlistmailingz at tropicsoft.com>> wrote:
>
>     I am using the latest clang built from source. I am seeing this
>     situation:
>
>     class XXX { some_non_copyable_non___assignable_member_type member; }
>
>     An object of class XXX never gets copied or assigned (it's a
>     singleton ) and yet clang is giving an errors of the form:
>
>     error: 'operator=' is a private member of
>     'some_non_assignable_member___type'.
>
>     and
>
>     error: field of type
>     'some_non_copyable_non___assignable_member_type' has private copy
>     constructor
>
>     My understanding of C++ is that if a member of a class is
>     non-copyable and non-assignable and an instance of that class is
>     never copied or assigned it is not an error even if the compiler
>     would be creating a default copy constructor and default assignment
>     operator when the class does not have user-defined versions.
>
>     The command line options to the clang++.exe compiler are:
>
>     -c -x c++ -O0 -g -fno-inline -Wall -pedantic -g
>
>
>
>
>     _________________________________________________
>     cfe-dev mailing list
>     cfe-dev at cs.uiuc.edu
>     <mailto:cfe-dev at cs.uiuc.edu>
>     http://lists.cs.uiuc.edu/__mailman/listinfo/cfe-dev
>     <http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>





More information about the cfe-dev mailing list