次のようなコードの使用に問題があります。
std::map<boost::tuple<int, int, int>, int> m;
boost::tuple<int, int, int> key = boost::make_tuple(1,2,3);
m.find(key);
コンパイラはエラーを認識しません。しかし、プログラムを開始すると、奇妙なセグメンテーション違反が発生します。そのため、それを引き起こすコード行を見つけたかったのです。それからGDBは私に言った:
Program received signal SIGSEGV, Segmentation fault.
0x0809f40a in boost::tuples::detail::lt<boost::tuples::cons<int,
boost::tuples::cons<int, boost::tuples::cons<int, boost::tuples::null_type> > >,
boost::tuples::cons<int, boost::tuples::cons<int, boost::tuples::cons<int,
boost::tuples::null_type> > > > (lhs=..., rhs=...)
at /usr/local/lib/boost_1_45_0/boost/tuple/tuple_comparison.hpp:73
73 lt(lhs.get_tail(), rhs.get_tail()));
残念ながら、これまでのところ、この種の問題に対する解決策は見つかりませんでした。
私がここで見逃したものを見た人はいますか?
編集:それで、さらに調査を行いました。問題の原因となっているオブジェクトは、ユーザー定義のものです。そして実際には、ベクトルでもエラーが発生するため、ブースト関連のものもマップの使用法も原因ではないようです!
class A {
void foo();
private:
std::vector<int> v;
}
void A::foo() {
...
v = std::vector<int>(); // Here already comes a segfault.
...
}
また、別のクラスでエラーを再現しようとしました。残念ながら、私はそこでエラーを引き起こすことができませんでした。
今gdbは私に言います:
Program received signal SIGSEGV, Segmentation fault.
0x010cae21 in free () from /lib/libc.so.6
(gdb) backtrace
#0 0x010cae21 in free () from /lib/libc.so.6
#1 0x00fd7441 in operator delete(void*) () from /usr/lib/libstdc++.so.6
#2 0x080668c7 in __gnu_cxx::new_allocator<int>::deallocate (this=0xbfffdb04,
__p=0x210bf) at /usr/include/c++/4.4/ext/new_allocator.h:95
#3 0x08064b8d in std::_Vector_base<int, std::allocator<int> >::_M_deallocate
(this=0xbfffdb04, __p=0x210bf, __n=105047440)
at /usr/include/c++/4.4/bits/stl_vector.h:146
#4 0x0806246a in std::_Vector_base<int, std::allocator<int> >::~_Vector_base
(this=0xbfffdb04, __in_chrg=<value optimized out>)
at /usr/include/c++/4.4/bits/stl_vector.h:132
#5 0x080604d4 in std::vector<int, std::allocator<int> >::~vector (this=0xbfffdb04,
__in_chrg=<value optimized out>)
at /usr/include/c++/4.4/bits/stl_vector.h:313
#6 0x0809e151 in ModelManager::emitSignal (this=0xbffff20f, o=crossroad, r=none,
restrID=-1, signal=add, id=-5, colStart=-1, colEnd=-1)
at .build_debug/src/model/modelmanager.cpp:103
コンパイラの設定が原因でしょうか?