egcs 1.0.3a template deduction bug

Reid M. Pinchback reidmp@MIT.EDU
Thu Jul 30 13:51:00 GMT 1998


I believe I've found a bug in how egcs 1.0.3a handles
deduction of template arguments in functions (the same
bug is in g++ 2.8.1).

Here is a small sample to show the problem.  If you look
in main(), there is a choice of three lines to uncomment
out before compiling.  The line currently active results
in a running program.  Either of the other two choices
gives an error message at compile time like:

// ------- error output ----------------------------

g++ -c bug1.cpp
as0: Error: bug1.cpp, line 6: stmt extends past logical end
      jsr $26,succ1__H1i1_RCt7natural1iY01_t7natural1i *1
as0: Error: bug1.cpp, line 6: stmt extends past logical end
      .ent succ1__H1i1_RCt7natural1iY01_t7natural1i *1
as0: Error: bug1.cpp, line 6: undefined assembler operation: succ1__H1i1_RCt7nat
ural1iY01_t7natural1i
     succ1__H1i1_RCt7natural1iY01_t7natural1i *1:
as0: Error: bug1.cpp, line 6: undefined assembler operation: $succ1__H1i1_RCt7na
tural1iY01_t7natural1i
     $succ1__H1i1_RCt7natural1iY01_t7natural1i *1..ng:
as0: Warning: bug1.cpp, line 6: .ent/.end block never defined the procedure name
      .end succ1__H1i1_RCt7natural1iY01_t7natural1i *1
*** Exit 1
Stop.

// ----------- source ----------------------------

/*
  file: bug.cpp

  to build and run:

    g++ -c bug.cpp
    g++ -o bug bug.o
*/

#include <iostream>

template <int i>
struct natural : public natural<i-1> {
  const int n;
  natural() : n(i) {}
};

struct natural<0> {
  const int n;
  natural() : n(0) {}
};

template <int i>
natural<i-1> pred(const natural<i>& n) {
  return natural<i-1>();
}

template <int i>
natural<i+1> succ1(const natural<i>& n) {
  return natural<i+1>();
}

template <class N>
N succ2(const N& n) { return n+1; }

main() {
  // NOTE: To test the bug, uncomment one
  //       of the following two lines,
  //       and comment out the third line
  //int n=pred(natural<1>()).n;
  //int n=succ1(natural<1>()).n;
  int n=succ2(1);
  cout << n << '\n';
}

// ------------- end -----------------------------
 
====================================================
= Reid M. Pinchback                                =
= I/T Delivery, MIT                                =
=                                                  =
= Email:   reidmp@mit.edu                          =
= URL:     http://web.mit.edu/reidmp/www/home.html =
====================================================




More information about the Gcc-bugs mailing list