public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Wolfgang Bangerth <bangerth@ices.utexas.edu>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c++/10437: "using namespace" at global scope creates incorrect code
Date: Fri, 25 Apr 2003 19:46:00 -0000	[thread overview]
Message-ID: <20030425194601.5074.qmail@sources.redhat.com> (raw)

The following reply was made to PR c++/10437; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ices.utexas.edu>
To: Dean Foster <foster@diskworld.wharton.upenn.edu>
Cc: gcc-gnats@gcc.gnu.org, <gcc@gcc.gnu.org>
Subject: Re: c++/10437: "using namespace" at global scope creates incorrect
 code
Date: Fri, 25 Apr 2003 14:37:44 -0500 (CDT)

 > I've shortened it down to about 50 lines.  (Took several 100 compiles.
 
 OK, I tested this and I now see two issues here. Number one:
 -----------------------
 namespace NS {
   template <class T> void foo (const T&);
 }
 
 template<class T> void bar() {
   foo (T());
 }
 
 using namespace NS;
 
 int main() {
  bar<int>();
 }
 -----------------------
 This compiles. Should it? At the point of declaration of bar(), NS::foo is 
 not visible, but the call is template dependent (i.e. two-stage name 
 lookup kicks in), so we also have to take into account everything that is 
 visible at the point of instantiation, where NS::foo _is_ visible, due to 
 the global scope using directive. I wasn't aware of the fact, though, that 
 using directives work retroactively for two-stage name lookup as well. 
 (icc tends to agree with me here, it rejects the code.)
 
 However, the code stops to compile if the "using" is moved inside main(). 
 I think that for visibility of foo inside bar, only symbols declared in the 
 scope of main, not inside it should be relevant, which would explain this. 
 Can someone confirm this?
 
 
 Point 2: Given the above -- this doesn't compile:
 ----------------------
 template <class T> struct X {
     typedef typename T::type_doesnt_exist type;
 };
 
 void foo(int);
 
 template <class T>
 typename X<T>::inexistent  foo (const T&);
 
 template<class T> void bar() {  foo(T());  }
 
 
 int main() { bar<int>(); }
 -----------------------
 
 The compiler says:
 g/x> ~/bin/gcc-3.4-pre/bin/c++ -c x.cc
 x.cc: In instantiation of `X<int>':
 x.cc:12:   instantiated from `void bar() [with T = int]'
 x.cc:16:   instantiated from here
 x.cc:4: error: `int' is not a class, struct, or union type
 
 Why isn't this just a SFINAE failure, which would lead to the silent 
 rejection of the foo template? (icc rejects this code as well, so I think 
 gcc should be right, but I don't understand why.)
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth              email:            bangerth@ices.utexas.edu
                                www: http://www.ices.utexas.edu/~bangerth/
 
 


             reply	other threads:[~2003-04-25 19:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-25 19:46 Wolfgang Bangerth [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-04-25 19:38 bangerth
2003-04-21 20:06 Wolfgang Bangerth
2003-04-21 19:26 Dean Foster
2003-04-21 15:06 bangerth
2003-04-19  0:36 dean

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=20030425194601.5074.qmail@sources.redhat.com \
    --to=bangerth@ices.utexas.edu \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@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).