GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 40160 - -fno-rtti vs _GLIBCXX_DEBUG
Summary: -fno-rtti vs _GLIBCXX_DEBUG
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: 4.5.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-15 14:02 UTC by Jay Foad
Modified: 2009-05-18 09:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-05-15 19:34:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jay Foad 2009-05-15 14:02:50 UTC
I get:

$ cat s.cpp
#include <string>
$ g++ -c -fno-rtti -D_GLIBCXX_DEBUG s.cpp
In file included from /usr/include/c++/4.3/debug/debug.h:155,
                 from /usr/include/c++/4.3/bits/stl_algobase.h:76,
                 from /usr/include/c++/4.3/bits/char_traits.h:46,
                 from /usr/include/c++/4.3/string:47,
                 from s.cpp:1:
/usr/include/c++/4.3/debug/formatter.h: In constructor ‘__gnu_debug::_Error_formatter::_Parameter::_Parameter(const __gnu_debug::_Safe_iterator<_Iterator, _Sequence>&, const char*, __gnu_debug::_Error_formatter::_Is_iterator)’:
/usr/include/c++/4.3/debug/formatter.h:218: error: cannot use typeid with -fno-rtti
/usr/include/c++/4.3/debug/formatter.h:224: error: cannot use typeid with -fno-rtti
/usr/include/c++/4.3/debug/formatter.h: In constructor ‘__gnu_debug::_Error_formatter::_Parameter::_Parameter(const _Type*&, const char*, __gnu_debug::_Error_formatter::_Is_iterator)’:
/usr/include/c++/4.3/debug/formatter.h:247: error: cannot use typeid with -fno-rtti
/usr/include/c++/4.3/debug/formatter.h: In constructor ‘__gnu_debug::_Error_formatter::_Parameter::_Parameter(_Type*&, const char*, __gnu_debug::_Error_formatter::_Is_iterator)’:
/usr/include/c++/4.3/debug/formatter.h:260: error: cannot use typeid with -fno-rtti
/usr/include/c++/4.3/debug/formatter.h: In constructor ‘__gnu_debug::_Error_formatter::_Parameter::_Parameter(const _Iterator&, const char*, __gnu_debug::_Error_formatter::_Is_iterator)’:
/usr/include/c++/4.3/debug/formatter.h:273: error: cannot use typeid with -fno-rtti
/usr/include/c++/4.3/debug/formatter.h: In constructor ‘__gnu_debug::_Error_formatter::_Parameter::_Parameter(const __gnu_debug::_Safe_sequence<_Sequence>&, const char*, __gnu_debug::_Error_formatter::_Is_sequence)’:
/usr/include/c++/4.3/debug/formatter.h:289: error: cannot use typeid with -fno-rtti
/usr/include/c++/4.3/debug/formatter.h: In constructor ‘__gnu_debug::_Error_formatter::_Parameter::_Parameter(const _Sequence&, const char*, __gnu_debug::_Error_formatter::_Is_sequence)’:
/usr/include/c++/4.3/debug/formatter.h:298: error: cannot use typeid with -fno-rtti

Shouldn't uses of typeid in the library be guarded with #ifdef _GXX_RTTI, or something?

I'm using g++ 4.3.2 on Debian lenny.
Comment 1 Paolo Carlini 2009-05-15 14:27:30 UTC
I get your point, indeed I implemented __GXX_RTTI and put it to good use in has_facet / use_facet. However, here, what happens to debug mode if typeid is not available? Is it still largely usable? If not, and I'm afraid is not, then probably the error is rather appropriate, we can maybe make it more clear, but it's essentially. Or you believe debug mode can be made to work also together with -fno-rtti?
Comment 2 Jay Foad 2009-05-15 14:37:30 UTC
I'm using debug mode to catch problems like v[i] where i >= v.size(). I think it would be very nice if this worked with -fno-rtti. I don't see why RTTI should be required to make this work. But then, I have no idea why typeid is being used in debug/formatter.h in the first place.

As a workaround, I am removing -fno-rtti from the command line when I build my project with libstdc++ debug mode enabled, but it is annoying to have to do this for a project that doesn't use RTTI.
Comment 3 Paolo Carlini 2009-05-15 14:48:28 UTC
Ok. In fact, being typeid used in formatter.h only (please confirm, if you can), I suspect not using it (replacing &typeid with 0) would only lead to worse error message, not more than that. Are you willing to experiment a bit with that? It would imply wrapping those place where _M_type is assigned with __GXX_RTTI, and also, careful, tweaking a bit src/debug.cc to not assert _M_type != 0, instead conditionalize consistently on that, have something like "<unknown type>" in its place. Please let me know...
Comment 4 Jay Foad 2009-05-15 15:39:12 UTC
> typeid used in formatter.h only (please confirm, if you can)

If I replace typeid(...) with 0 in formatter.h then I can at least compile the following with -fno-rtti -D_GLIBCXX_DEBUG:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <complex.h>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <cxxabi-forced.h>
#include <cxxabi.h>
#include <deque>
#include <exception>
#include <exception_defines.h>
#include <fenv.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <tgmath.h>
#include <typeinfo>
#include <utility>
#include <vector>

I'm not really in a position to test changes to libstdc++.so, sorry.
Comment 5 Paolo Carlini 2009-05-15 19:34:10 UTC
Ok, thanks. I'll fix it as I said earlier today.
Comment 6 paolo@gcc.gnu.org 2009-05-15 22:25:38 UTC
Subject: Bug 40160

Author: paolo
Date: Fri May 15 22:25:24 2009
New Revision: 147599

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147599
Log:
2009-05-15  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/40160
	* include/debug/formatter.h (_Parameter::_Parameter): Don't use
	typeid when __GXX_RTTI is undefined.
	* src/debug.cc (_Error_formatter::_Parameter::_M_print_field): Adjust
	for null _M_variant._M_iterator._M_type,
	_M_variant._M_iterator._M_seq_type, _M_variant._M_sequence._M_type.
	* testsuite/21_strings/basic_string/40160.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/40160.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/debug/formatter.h
    trunk/libstdc++-v3/src/debug.cc

Comment 7 Paolo Carlini 2009-05-15 22:27:02 UTC
Fixed.
Comment 8 Jay Foad 2009-05-18 09:46:25 UTC
Thanks Paolo!