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]
Other format: [Raw text]

[Bug c++/16037] New: Incorrect C++ template code compiles without error nor warning and can be exectuted


Hello experts,

The 3 lines at the end of the C++ file Test6.C should not be compiled nor be
executed (one would think). Neither g++ version 3.4.0 nor 3.3.2 catch this error.

g++ Test6.C

I run Linux version 2.4.20-20.9smp (bhcompile@stripples.devel.redhat.com) (gcc
version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 SMP Mon Aug 18 11:32:15 EDT 2003

Thanks,

Burkhard Militzer

-------------------------------------------------------------------------------
Test6.C
-----------------------------------------------------------------------------
#include <iostream>

template <class T, int n> 
class ShortVector {
 public:
  T v[n];
};

template <int DIM>
class BasicPoint : public ShortVector<double,DIM> {
 public:
  BasicPoint(const double p) {
    for(int i=0; i<DIM; i++) 
      this->v[i]=p;
  }
  
};

const int NDIM=3;

class P {
 public:
  void ReadP(const BasicPoint<NDIM> & scaling) {
    for(int i=0; i<NDIM; i++) {
      std::cout << scaling.v[i] << std::endl;
    }
  };
};

int main() {
  BasicPoint<NDIM> scaling(1.0);
  int i;
  double d;
  bool b;

  P p;
  p.ReadP(scaling); // ok
  p.ReadP(b); // should not compile nor be executed
  p.ReadP(d); // should not compile nor be executed
  p.ReadP(i); // should not compile nor be executed
  return 0;
}

-- 
           Summary: Incorrect C++ template code compiles without error nor
                    warning and can be exectuted
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: militzer at gl dot ciw dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16037


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