public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: c++/10437: "using namespace" at global scope creates incorrect code
       [not found] <20030422115901.19635.qmail@diskworld.wharton.upenn.edu>
@ 2003-04-25 20:22 ` Wolfgang Bangerth
  0 siblings, 0 replies; only message in thread
From: Wolfgang Bangerth @ 2003-04-25 20:22 UTC (permalink / raw)
  To: Dean Foster; +Cc: gcc-gnats, gcc


> 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/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-04-25 19:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20030422115901.19635.qmail@diskworld.wharton.upenn.edu>
2003-04-25 20:22 ` c++/10437: "using namespace" at global scope creates incorrect code Wolfgang Bangerth

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).