public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rockeet at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/23885] incorrect template two-stage name-lookup
Date: Tue, 13 Dec 2011 09:39:00 -0000	[thread overview]
Message-ID: <bug-23885-4-oAu3ajQwic@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-23885-4@http.gcc.gnu.org/bugzilla/>

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

rockeet <rockeet at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rockeet at gmail dot com

--- Comment #9 from rockeet <rockeet at gmail dot com> 2011-12-13 09:35:29 UTC ---
///// Code Begin
#include <stdio.h>

class A {}; void f(A) { printf("%s\n", __PRETTY_FUNCTION__); }
class B {};
template<class T> void f(T) { printf("%s\n", __PRETTY_FUNCTION__); }

// now g(T) knew A,B,int,...
// phase 1 lookup just success for f(A)
template<class T> void g(T x) { f(x); }

// after definition of g(T) and class B
void f(B) { printf("%s\n", __PRETTY_FUNCTION__); }

void f(int x) { printf("%s\n", __PRETTY_FUNCTION__); }
void f(int*x) { printf("%s\n", __PRETTY_FUNCTION__); }

int main(int argc, char** argv) {
    g(A());   // should always(phase 1 and phase 2) be OK
    g(B());   // f(B) definition is after g(T) definition, phase 1 just got
f(A) and f(T)
    g(B());   //      but phase 2 got f(B)
    g(100);   // intend to let g calling f(int), but got f(T) in g++ 4.1.2 and
4.6.0, 4.7.0, others not tested
    g(&argc); // intention: similar as g(100)
    return 0;
}
///// Code End

The output of above code shown that "associated sets of namespaces and
classes of fundamental types are both empty" is really true! But pre g++ 3.4.6
and clang treat fundamental types as same as user defined types.

//// Begin Compile With g++ 4.6.0
$g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.6.0-src/configure --prefix=/opt --with-gmp=/opt
--with-mpfr=/opt --with-mpc=/opt --with-ppl=/opt --with-cloog=/opt
--with-local-prefix=/opt --enable-languages=c,c++
Thread model: posix
gcc version 4.6.0 (GCC) 
$ g++ twophaselookup2.cpp
$ ./a.out 
//// End Compile With g++ 4.6.0

//// Begin Compile With g++ 3.4.6
void f(A)
void f(B)
void f(B)
void f(int)
void f(int*)
//// Begin Compile With g++ 3.4.6

apple clang produced the same result as g++ 3.4.6


       reply	other threads:[~2011-12-13  9:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-23885-4@http.gcc.gnu.org/bugzilla/>
2011-12-13  9:39 ` rockeet at gmail dot com [this message]
2011-12-13 10:07 ` rockeet at gmail dot com
2012-10-12 15:16 ` paolo.carlini at oracle dot com
2013-05-20 10:00 ` paolo.carlini at oracle dot com
     [not found] <bug-23885-11356@http.gcc.gnu.org/bugzilla/>
2006-01-29  2:02 ` pinskia at gcc dot gnu dot org
2007-05-30 18:01 ` fang at csl dot cornell dot edu
2007-05-30 21:03 ` martin dot audet at imi dot cnrc-nrc dot gc dot ca
2007-05-31  9:49 ` andrew dot stubbs at st dot com
2010-01-06 19:42 ` jason at gcc dot gnu dot org
2005-09-14 18:54 [Bug c++/23885] New: " martin dot audet at imi dot cnrc-nrc dot gc dot ca
2005-09-14 19:04 ` [Bug c++/23885] " pinskia at gcc dot gnu dot org
2005-09-14 20:37 ` martin dot audet at imi dot cnrc-nrc dot gc dot ca
2005-09-14 20:42 ` pinskia at gcc dot gnu dot org
2005-09-15 19:35 ` pinskia at gcc dot gnu dot org
2005-10-01 15:15 ` redi at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-23885-4-oAu3ajQwic@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).