This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Code that worked in gcc-2.95.2 but not in 2.96...


I'm trying to get my code ready for gcc 3 and the new stdc++lib 3 but
lots of stuff simple won't compiler/link properly. Many issues are just
a more strict compiler (which is good) but a few things I just can't
figure. The attached code fails to link although everything its looking
for seems quite explicitly defined. Can some one rent me a clue as to
what my problem is? This is being built with egcs-20000911 configured
with '--enable-shared --enable-libstdcxx-v3' in a linux 2.2.13 kernel
for i686.

    thanx & later,

        Ben Scherrey
//
//  default.cpp     -   Testing default parms (or null string values).
//

#include <iostream>
#include <iomanip>
#include <stdexcept>
#include <string>
#include <strstream>

class Default : public exception
{
static const char* defaulttext;

public:

    Default( void ) throw() { msg = defaulttext; }
    
    Default( const string& what, const string file = "", const unsigned int line = 0 ) throw()
    {
        strstream AMsg;
        AMsg << defaulttext << what;
        if( file.size() )
        {
            AMsg << setfill(' ') << "\t" << file;
            
            if( line )
            {
                AMsg << " : " << setw( 4 ) << line;
            }
        }
   
        AMsg << ends;
        msg = AMsg.str();
    }
    
    virtual const char* what( void ) const throw() { return msg.c_str(); }
    
    friend ostream& operator<<( ostream& o, const Default& d );
    
private:

    string msg;
    
};

const char* defaulttext = "Default exception!";

ostream& operator <<( ostream& o, const Default& d ) { o << d.what(); return o; }


int main( int argc, char* argv[] )
{
    cout << "Constructing an initial Default exception." << endl;
    Default X( "X Exception @", __FILE__, __LINE__ );
    cout << "X( 'X Exception @', __FILE__, __LINE__ ) = " << X << endl;
    Default Y( "Y Exception" );
    cout << "Y( 'Y Exception' ) = " << Y << endl;
    
    return 0;
}

//
// eof(default.cpp)
//
/tmp/ccMlXncj.o: In function `Default::Default(basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> > const &, basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >, unsigned int)':
/tmp/ccMlXncj.o(.Default::gnu.linkonce.t.(basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> > const &, basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >, unsigned int)+0x51): undefined reference to `Default::defaulttext'
collect2: ld returned 1 exit status

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]