Arthur Schwarz <[email protected]> writes:
> # include <fstream>
> # include <istream>
>
> using namespace std;
>
> ifstream x;
> ifstream& y = x;
>
> int main(int argc, char** argv) {
> y = x;
> return 0;
> }
>
> g++.3.4.4 output
> m1.cpp: In member function `std::basic_ios<char, std::char_traits<char> >&
> std::basic_ios<char, std::char_traits<char> >::operator=(const
> std::basic_ios<char, s
> td::char_traits<char> >&)':
> /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ios_base.h:784: error:
> `std::ios_base& std::ios_base::operator=(const std::ios_base&)' is private
> m1.cpp:10: error: within this context
> m1.cpp: In member function `std::basic_filebuf<char, std::char_traits<char>
> >& std::basic_filebuf<char, std::char_traits<char> >::operator=(const
> std::basic_fil
> ebuf<char, std::char_traits<char> >&)':
> /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/streambuf:776: error:
> `std::basic_streambuf<_CharT, _Traits>& std::basic_streambuf<_CharT,
> _Traits>::operator=(con
> st std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits =
> std::char_traits<char>]' is private
> m1.cpp:10: error: within this context
>
> Almost indecipherable. The error is that operator=() is private.
> "error: assignment illegal, operator '=' private in ifstream"
gcc 3.4.4 is a bit old. I tried current mainline, and I got this:
In file included from
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ios:39,
from
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/istream:40,
from
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/fstream:40,
from foo.cc:1:
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/ios_base.h:
In member function ‘std::basic_ios<char>&
std::basic_ios<char>::operator=(const std::basic_ios<char>&)’:
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/ios_base.h:793:
error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is
private
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:47:
error: within this context
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:
In member function ‘std::basic_istream<char>&
std::basic_istream<char>::operator=(const std::basic_istream<char>&)’:
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:53:
note: synthesized method ‘std::basic_ios<char>&
std::basic_ios<char>::operator=(const std::basic_ios<char>&)’ first required
here
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:
In member function ‘std::basic_ifstream<char>&
std::basic_ifstream<char>::operator=(const std::basic_ifstream<char>&)’:
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:81:
note: synthesized method ‘std::basic_istream<char>&
std::basic_istream<char>::operator=(const std::basic_istream<char>&)’ first
required here
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/streambuf:
In member function ‘std::basic_filebuf<char>&
std::basic_filebuf<char>::operator=(const std::basic_filebuf<char>&)’:
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/streambuf:778:
error: ‘std::basic_streambuf<_CharT, _Traits>::__streambuf_type&
std::basic_streambuf<_CharT, _Traits>::operator=(const
std::basic_streambuf<_CharT, _Traits>::__streambuf_type&) [with _CharT = char,
_Traits = std::char_traits<char>, std::basic_streambuf<_CharT,
_Traits>::__streambuf_type = std::basic_streambuf<char>]’ is private
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:78:
error: within this context
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:
In member function ‘std::basic_ifstream<char>&
std::basic_ifstream<char>::operator=(const std::basic_ifstream<char>&)’:
/home/iant/gcc/install/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/iosfwd:81:
note: synthesized method ‘std::basic_filebuf<char>&
std::basic_filebuf<char>::operator=(const std::basic_filebuf<char>&)’ first
required here
foo.cc: In function ‘int main(int, char**)’:
foo.cc:10: note: synthesized method ‘std::basic_ifstream<char>&
std::basic_ifstream<char>::operator=(const std::basic_ifstream<char>&)’ first
required here
So the compiler is trying to show you how it got to the point where it
needed the private function. I have to agree that it does rather
obscure the issue, though. At least "std::char_traits<char>" is gone.
Filed as http://gcc.gnu.org/PR39728 .
> using namespace std;
>
> ifstream x;
> ifstream y();
>
> int main(int argc, char** argv) {
> return 0;
> }
>
> g++.3.4.4 output
> m2.cpp:4: error: `ifstream' does not name a type
> m2.cpp:5: error: `ifstream' does not name a type
>
> Succint and clear message, however it might be clearer
> to say that "'ifstream' not found" since the message
> says that 'ifstream' may be something other than a
> type.
>
> "error: ifstream not found"
> "note: candidates are in #include <fstream>"
Mainline gcc has the same message. I agree that "not found" seems
clearer. I'm not sure I agree about suggesting header files; that is
the kind of thing which will work well in some environments but fail
badly in others.
Suggesting "not defined" in http://gcc.gnu.org/PR 39729 .
> # include <istream>
> # include <istream>
>
> using namespace std;
>
> ifstream x;
> ifstream y();
>
> int main(int argc, char** argv) {
> return 0;
> }
>
> g++3.4.4 messaging
> m3.cpp:6: error: aggregate `std::ifstream x' has incomplete type and cannot
> be defined
> m3.cpp:6: error: storage size of `x' isn't known
>
> Messaging not clear. The naive issue is the 'ifstream' not found.
> 'std::ifstream' not
> found. 'std::ifstream x' is confusing.
>
> If 'std::ifstream' not found, why is 'std::ifstream y();' legal?
>
> "error: ifstream incomplete in 'istream'.
Mainline says
foo.cc:6: error: aggregate ‘std::ifstream x’ has incomplete type and cannot be
defined
So at least we've lost the useless message about 'x'. But, yes, this
message should also be simplified.
Filed as http://gcc.gnu.org/PR39730 .
Thanks.
Ian