This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
assert in constructor causes chaos
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: assert in constructor causes chaos
- From: Samuel Krempp <krempp at cmla dot ens-cachan dot fr>
- Date: Thu, 12 Jul 2001 00:43:23 +0200 (CEST)
The bug was reproduced with the following g++ :
gcc version 3.1 20010624 (experimental)
gcc version 3.1 20010707 (experimental)
i686-pc-linux-gnu
and is not present in
gcc version 3.0 20010402 (Debian prerelease)
The code is fairly simple.
putting an assert in the constructor seems to cause the ctor to be called
twice (so the second time, it fails..)
Also, the bug disappears when the class is not a template.
hth,
--
Sam
#include <cassert>
template<class charT >
class basic_format {
private:
int style;
static const char ordered = 1, short_notation = 2;
public:
basic_format(const charT* str, bool s_notation=false)
: style(0)
{ //std::cerr<<" ctor "<<s_notation<<" style :"<<style<<std::endl;
assert( style == 0);
if(style!=0) int n = *(int*) 0;
if(s_notation) style |= short_notation;
style=5;}
~basic_format() { }
private:
basic_format& operator= (const basic_format&);
basic_format( const basic_format&);
};
int main(){
using namespace std;
basic_format<char> a("blabla",true);
//cerr<<" a done \n";
}