Bug 38762 - template sees an overload that should not be visible at point of instantiation
Summary: template sees an overload that should not be visible at point of instantiation
Status: RESOLVED DUPLICATE of bug 16635
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-08 00:35 UTC by Doug Morgan
Modified: 2009-01-09 20:27 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Morgan 2009-01-08 00:35:52 UTC
I don't see how to include the requested *.i* file with this web page.  So, you just get the source and compilation stdout.  Here is the program that does what seems to be the wrong thing:
-----
// Somehow a function overload is visible that should not have been seen at
// the point of instantiation.
// Reproduce bug with:
// % /usr/bin/g++ -v -save-temps -ansi -pedantic -Wall temp1.cpp
// % ./a.out
// int
// The output should be:
// double

#include <iostream>

template<class T> void g(T a) {  h(a); }
void h(double) { std::cout << "double" << std::endl; }

int main(int argc, char* argv[])
{
  g(1);
  return 0;
}

void h(int) { std::cout << "int" << std::endl; }

-----
Here is the stdout from compilation (the same error happens with 4.1.3 also):

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
 /usr/lib/gcc/x86_64-linux-gnu/4.2.4/cc1plus -E -quiet -v -D_GNU_SOURCE temp1.cpp -mtune=generic -ansi -pedantic -Wall -fpch-preprocess -o temp1.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.2
 /usr/include/c++/4.2/x86_64-linux-gnu
 /usr/include/c++/4.2/backward
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.2.4/include
 /usr/include
End of search list.
 /usr/lib/gcc/x86_64-linux-gnu/4.2.4/cc1plus -fpreprocessed temp1.ii -quiet -dumpbase temp1.cpp -mtune=generic -ansi -auxbase temp1 -pedantic -Wall -ansi -version -fstack-protector -fstack-protector -o temp1.s
GNU C++ version 4.2.4 (Ubuntu 4.2.4-1ubuntu3) (x86_64-linux-gnu)
	compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu3).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 2328a9860f8ee3842b3eeb9e852e4412
 as --traditional-format -V -Qy -o temp1.o temp1.s
GNU assembler version 2.18.0 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.18.0.20080103
 /usr/lib/gcc/x86_64-linux-gnu/4.2.4/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.2.4/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.2.4 -L/usr/lib/gcc/x86_64-linux-gnu/4.2.4 -L/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../.. temp1.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.2.4/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/crtn.o
Comment 1 Andrew Pinski 2009-01-09 20:27:39 UTC

*** This bug has been marked as a duplicate of 16635 ***