swapnils3112 / google-concurrency-library

Automatically exported from code.google.com/p/google-concurrency-library
0 stars 0 forks source link

Output stream_mutex should not require a copyable object. #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a non-copyable object.
2. Output the object using a stream_mutex<std::ostream>
3. Compile.

What is the expected output? What do you see instead?

Compilation should succeed, however the compiler reports fails indicating
that it is attempting to copy a non-copyable object.

What version of the product are you using? On what operating system?

scrolllinux3:~/svn/google-concurrency-library-read-only 0:13> svn info
Path: .
URL: http://google-concurrency-library.googlecode.com/svn
Repository Root: http://google-concurrency-library.googlecode.com/svn
Repository UUID: 003f9db4-d5f8-dca4-bccd-e9ef3f936871
Revision: 121
Node Kind: directory
Schedule: normal
Last Changed Author: alasdair.mackintosh
Last Changed Rev: 121
Last Changed Date: 2013-04-18 19:44:32 -0500 (Thu, 18 Apr 2013)

scrolllinux3:~/svn/google-concurrency-library-read-only 0:14> cat /etc/issue
Ubuntu 12.04.2 LTS \n \l

Please provide any additional information below.

I added the following code to testing/stream_mutex_test.cc (line
numbers added for reference) and attempted to compile under gcc 4.6.4.

    26  struct NonCopyable
    27  {
    28      NonCopyable() {};
    29  private:
    30      NonCopyable(const NonCopyable&) {};
    31  };
    32
    33  std::ostream& operator<<(std::ostream& os, const NonCopyable&)
    34  {
    35      return os << "non-copyable";
    36  }
    37
    38  void noncopyable(stream_mutex<std::ostream>& mstream)
    39  {
    40      NonCopyable v;
    41      mstream << v << std::endl;
    42  }
    43
    44  void noncopyable(std::ostream& ostream)
    45  {
    46      NonCopyable v;
    47      ostream << v << std::endl;
    48  }

Compilation fails in the stream_mutex<std::ostream> version of noncopyable:

make[1]: Entering directory 
`/localhome/scroll/svn/google-concurrency-library-read-only/dbg98'
g++ -MMD -MP -Wall -Werror -Wno-error=c++0x-compat -I. -I../include -g3 
-std=c++98 -Wno-c++0x-compat -I../third_party/googletest/include 
-I../third_party/googlemock/include ../testing/stream_mutex_test.cc -c -o 
stream_mutex_test.o
../testing/stream_mutex_test.cc: In function ‘void 
noncopyable(stream_mutex<std::basic_ostream<char> >&)’:
../testing/stream_mutex_test.cc:30:5: error: ‘NonCopyable::NonCopyable(const 
NonCopyable&)’ is private
../testing/stream_mutex_test.cc:41:16: error: within this context
../include/stream_mutex.h:97:22: error:   initializing argument 2 of 
‘stream_guard<Stream> operator<<(stream_mutex<Stream>&, T) [with Stream = 
std::basic_ostream<char>, T = NonCopyable]’
make[1]: *** [stream_mutex_test.o] Error 1

Note if I comment out lines 38-42, compilation succeeds (for the std::ostream 
version of noncopyable).

Original issue reported on code.google.com by stephen....@gmail.com on 15 May 2013 at 12:28