This is the mail archive of the gcc-bugs@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]

bad code silently compiled by egcs


The following code compiles without a warning:
1. data_t should not be visible in B
2. B's constructor calls an A constructor which is not defined. 

See the "//!!" comments.
-- 
Ovidiu

toucan:~/work/C++/bug3> uname -a
Linux toucan.physics.utoronto.ca 2.0.36 #3 Sat Jan 9 19:07:50 EST 1999
i686 unknown
toucan:~/work/C++/bug3> g++ -v
Reading specs from
/usr/local/Packages/lang/egcs/install/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.93.12/specs
gcc version egcs-2.93.12 19990314 (gcc2 ss-980929 experimental)
toucan:~/work/C++/bug3> cat main.cc
#include <iostream>

template <class T>
class A {
private:
  typedef T       value_t;
  typedef value_t data_t[2];
public:
  A(data_t const & d){
    d_[0] = d[0] ; d_[1] = d[1];
  }
  void print(ostream &s) const {
    s << d_[0] << "\t" << d_[1] << endl;
  }
protected:
  data_t d_;
};

template <class T>
class B : public A<T>{
public:
  // !! data_t should not be available here
  // !! there is no A constructor which accepts a data_t const
  B(data_t const d) : A<T>(d) {}
};

int
main(){
  B<double>::data_t d;
  d[0] = 13 ; d[1] = 42;
  B<double> b(d);
  b.print(cout);
}
toucan:~/work/C++/bug3> g++ -ansi -W -Wall -pipe -o exe main.cc
toucan:~/work/C++/bug3> exe
4.85606e-270    4.85199e-270


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