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++/26916] New: [4.1/4.2 Regression] template/overloaded function lookup


It seems that template function overloading/argument dependent lookup now
depends on declaration order. If this is right or not I don't know yet, but it
changed without notice. consider this small piece of code:

#include <string>
#include <iostream>
#include <sstream>

template<typename T> void add_field(T  const & value) {
  static int counter;
  std::cout << "template \n";
  if (++counter < 5) {// avoid crash!!
    std::stringstream tmp;
    tmp << value;
    add_field(tmp.str());
  } else {
    std::cout << "would crash here \n";
  }
}
// put this before the template and get desired behaviour
void add_field(std::string const &value) {
  std::cout << "overload\n";
}

int main () {
  add_field ( "value");
  return 0;
}


on g++ < 4.1.0 (tested with 3.2.3, 3.3.2, 3.4.3 and 4.0.2) this program prints:
template
overload

while on 4.1.0 it prints
/a.out
template
template
template
template
template
template
would crash here


Changing the order of the two functions restores the old behaviour, but I'd say
this is a regression.


-- 
           Summary: [4.1/4.2 Regression] template/overloaded function lookup
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Michael dot Teske at swissrisk dot com
  GCC host triplet: i386-redhat-linux/sparc-sun-solaris2.8
GCC target triplet: i386-redhat-linux/sparc-sun-solaris2.8


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


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