Closed GoogleCodeExporter closed 9 years ago
Thanks for the bug report.
Very odd. I suspect it's a bug (or maybe a misfeature) in your compiler or in
your C++ standard library.
It looks like File objects can be implicitly converted to int; but there's no
such conversion operator declared in the File class itself, so it must have
been derived from std::fstream.
Can you tell me if test_fstream_to_int.cc can be compiled with your clang++?
Here (Linux, clang 3.2) it fails as expected:
$ clang++ test_fstream_to_int.cc
test_fstream_to_int.cc:6:4: error: invalid operands to binary expression
('std::fstream' (aka 'basic_fstream<char>') and 'int')
f + 42;
~ ^ ~~
But anyway, the attached patch should hopefully fix the problem.
Original comment by jwilk@jwilk.net
on 23 Nov 2013 at 5:27
Attachments:
Thanks for the quick replay... :-)
Your test case on OSX 10.9 Mavericks builds with a warning:
$ clang++ test_fstream_to_int.cc
test_fstream_to_int.cc:6:4: warning: expression result unused [-Wunused-value]
f + 42;
~ ^ ~~
1 warning generated.
being,
$ clang++ -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Instead, trying on the same system, with g++ 4.8.2 (installed with as MacPorts
port), it fails:
$ g++ test_fstream_to_int.cc
test_fstream_to_int.cc: In function 'int main(int, char**)':
test_fstream_to_int.cc:6:4: error: no match for 'operator+' (operand types are
'std::fstream {aka std::basic_fstream<char>}' and 'int')
f + 42;
^
test_fstream_to_int.cc:6:4: note: candidates are:
In file included from /opt/local/include/gcc48/c++/string:52:0,
from /opt/local/include/gcc48/c++/bits/locale_classes.h:40,
from /opt/local/include/gcc48/c++/bits/ios_base.h:41,
from /opt/local/include/gcc48/c++/ios:42,
from /opt/local/include/gcc48/c++/istream:38,
from /opt/local/include/gcc48/c++/fstream:38,
from test_fstream_to_int.cc:1:
/opt/local/include/gcc48/c++/bits/basic_string.h:2418:5: note: template<class
_CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc>
std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
^
/opt/local/include/gcc48/c++/bits/basic_string.h:2418:5: note: template
argument deduction/substitution failed:
test_fstream_to_int.cc:6:6: note: 'std::fstream {aka
std::basic_fstream<char>}' is not derived from 'const std::basic_string<_CharT,
_Traits, _Alloc>'
f + 42;
^
In file included from /opt/local/include/gcc48/c++/string:52:0,
from /opt/local/include/gcc48/c++/bits/locale_classes.h:40,
from /opt/local/include/gcc48/c++/bits/ios_base.h:41,
from /opt/local/include/gcc48/c++/ios:42,
from /opt/local/include/gcc48/c++/istream:38,
from /opt/local/include/gcc48/c++/fstream:38,
from test_fstream_to_int.cc:1:
/opt/local/include/gcc48/c++/bits/basic_string.h:2402:5: note: template<class
_CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc>
std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/opt/local/include/gcc48/c++/bits/basic_string.h:2402:5: note: template
argument deduction/substitution failed:
test_fstream_to_int.cc:6:6: note: 'std::fstream {aka
std::basic_fstream<char>}' is not derived from 'const std::basic_string<_CharT,
_Traits, _Alloc>'
f + 42;
^
In file included from /opt/local/include/gcc48/c++/string:53:0,
from /opt/local/include/gcc48/c++/bits/locale_classes.h:40,
from /opt/local/include/gcc48/c++/bits/ios_base.h:41,
from /opt/local/include/gcc48/c++/ios:42,
from /opt/local/include/gcc48/c++/istream:38,
from /opt/local/include/gcc48/c++/fstream:38,
from test_fstream_to_int.cc:1:
/opt/local/include/gcc48/c++/bits/basic_string.tcc:708:5: note: template<class
_CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc>
std::operator+(_CharT, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
^
/opt/local/include/gcc48/c++/bits/basic_string.tcc:708:5: note: template
argument deduction/substitution failed:
test_fstream_to_int.cc:6:6: note: mismatched types 'const
std::basic_string<_CharT, _Traits, _Alloc>' and 'int'
f + 42;
^
In file included from /opt/local/include/gcc48/c++/string:53:0,
from /opt/local/include/gcc48/c++/bits/locale_classes.h:40,
from /opt/local/include/gcc48/c++/bits/ios_base.h:41,
from /opt/local/include/gcc48/c++/ios:42,
from /opt/local/include/gcc48/c++/istream:38,
from /opt/local/include/gcc48/c++/fstream:38,
from test_fstream_to_int.cc:1:
/opt/local/include/gcc48/c++/bits/basic_string.tcc:692:5: note: template<class
_CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc>
std::operator+(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator+(const _CharT* __lhs,
^
/opt/local/include/gcc48/c++/bits/basic_string.tcc:692:5: note: template
argument deduction/substitution failed:
test_fstream_to_int.cc:6:6: note: mismatched types 'const _CharT*' and
'std::basic_fstream<char>'
f + 42;
^
In file included from /opt/local/include/gcc48/c++/string:52:0,
from /opt/local/include/gcc48/c++/bits/locale_classes.h:40,
from /opt/local/include/gcc48/c++/bits/ios_base.h:41,
from /opt/local/include/gcc48/c++/ios:42,
from /opt/local/include/gcc48/c++/istream:38,
from /opt/local/include/gcc48/c++/fstream:38,
from test_fstream_to_int.cc:1:
/opt/local/include/gcc48/c++/bits/basic_string.h:2365:5: note: template<class
_CharT, class _Traits, class _Alloc> std::basic_string<_CharT, _Traits, _Alloc>
std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const
std::basic_string<_CharT, _Traits, _Alloc>&)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/opt/local/include/gcc48/c++/bits/basic_string.h:2365:5: note: template
argument deduction/substitution failed:
test_fstream_to_int.cc:6:6: note: 'std::fstream {aka
std::basic_fstream<char>}' is not derived from 'const std::basic_string<_CharT,
_Traits, _Alloc>'
f + 42;
^
In file included from /opt/local/include/gcc48/c++/bits/stl_algobase.h:67:0,
from /opt/local/include/gcc48/c++/bits/char_traits.h:39,
from /opt/local/include/gcc48/c++/ios:40,
from /opt/local/include/gcc48/c++/istream:38,
from /opt/local/include/gcc48/c++/fstream:38,
from test_fstream_to_int.cc:1:
/opt/local/include/gcc48/c++/bits/stl_iterator.h:333:5: note: template<class
_Iterator> std::reverse_iterator<_Iterator> std::operator+(typename
std::reverse_iterator<_Iterator>::difference_type, const
std::reverse_iterator<_Iterator>&)
operator+(typename reverse_iterator<_Iterator>::difference_type __n,
^
/opt/local/include/gcc48/c++/bits/stl_iterator.h:333:5: note: template
argument deduction/substitution failed:
test_fstream_to_int.cc:6:6: note: mismatched types 'const
std::reverse_iterator<_Iterator>' and 'int'
f + 42;
^
For completeness,
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin13/4.8.2/lto-wrapp
er
Target: x86_64-apple-darwin13
Configured with:
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org
_release_tarballs_ports_lang_gcc48/gcc48/work/gcc-4.8.2/configure
--prefix=/opt/local --build=x86_64-apple-darwin13
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.8
--with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local
--enable-cloog-backend=isl --disable-cloog-version-check
--enable-stage1-checking --disable-multilib --enable-lto
--enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld
--with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket
--with-pkgversion='MacPorts gcc48 4.8.2_0'
Thread model: posix
gcc version 4.8.2 (MacPorts gcc48 4.8.2_0)
So I have tried to build pdf2djvu with your patch,
$ wgets https://pdf2djvu.googlecode.com/files/pdf2djvu_0.7.17.tar.gz
$ tar -xvf pdf2djvu_0.7.17.tar.gz
$ cd pdf2djvu-0.7.17/
$ patch system.cc ../issue88.diff
patching file system.cc
patching file system.hh
(I needed also this patch:
--- tools/xml2c~ 2013-05-30 22:22:26.000000000 +0200
+++ tools/xml2c 2013-11-23 20:18:06.000000000 +0100
@@ -6,7 +6,7 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
-exec sed \
+exec gsed \
-e '/<!--# *\(.*\) *#-->/ { s//\1/; b; }' \
-e '/<!--.*-->/ { s///g; b; }' \
-e 's/\\\\/\\\\/g' \
)
$ ./configure CC=clang CXX=clang++
$ make
Now it builds and seems to work (I have tried with some PDF file..)
Ciao,
Angelo.
Original comment by graziosi...@gmail.com
on 23 Nov 2013 at 7:28
tools/xml2c indeed doesn't work with non-GNU sed. This should hopefully be
fixed in r9e673a76694d.
I've been able to reproduce the build failure using clang++ with the
-std=libc++ option. I suppose this is the default on OSX.
The problem appears to be that in C++98 mode libc++'s defines the following
operator for std::basic_ios:
operator bool() const {return !fail();}
This makes objects deriving from std::basic_ios implicitly convertible to int.
This does not happen in C++11 mode (-std=gnu++11), because then the operator is
declared as:
explicit operator bool() const {return !fail();}
This also doesn't happen in GCC, since it implements "void*()" conversion
operator instead, as required by the C++98 standard:
operator void*() const
{ return this->fail() ? 0 : const_cast<basic_ios*>(this); }
Original comment by jwilk@jwilk.net
on 27 Nov 2013 at 11:53
Thanks for clarification :)
Ciao,
Angelo.
Original comment by graziosi...@gmail.com
on 27 Nov 2013 at 1:39
Typo in message #3: instead of "-std=libc++" it should be "-stdlib=libc++".
Original comment by jwilk@jwilk.net
on 13 Apr 2014 at 5:18
With he attached file , when i compile the code the clang++ compiler , getting
error with "no viable operator overload" with -stdlib=libc++.
Iam using clang version of 5.0 and if i use clang version of 5.1 , the problem
is resolved. Is it a clang compiler bug
Original comment by emb.mal...@gmail.com
on 4 Jun 2014 at 7:53
Attachments:
Should be fixed in pdf2djvu 0.7.18.
Original comment by jwilk@jwilk.net
on 18 Dec 2014 at 1:00
Original issue reported on code.google.com by
graziosi...@gmail.com
on 22 Nov 2013 at 8:51