This is the mail archive of the gcc@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]

Re: c++/10437: "using namespace" at global scope creates incorrectcode


> 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 at ices dot utexas dot edu
                               www: http://www.ices.utexas.edu/~bangerth/



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