From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5093 invoked by alias); 25 Apr 2003 19:46:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 5075 invoked by uid 71); 25 Apr 2003 19:46:01 -0000 Date: Fri, 25 Apr 2003 19:46:00 -0000 Message-ID: <20030425194601.5074.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Wolfgang Bangerth Subject: Re: c++/10437: "using namespace" at global scope creates incorrect code Reply-To: Wolfgang Bangerth X-SW-Source: 2003-04/txt/msg01129.txt.bz2 List-Id: The following reply was made to PR c++/10437; it has been noted by GNATS. From: Wolfgang Bangerth To: Dean Foster Cc: gcc-gnats@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 void foo (const T&); } template void bar() { foo (T()); } using namespace NS; int main() { bar(); } ----------------------- 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 struct X { typedef typename T::type_doesnt_exist type; }; void foo(int); template typename X::inexistent foo (const T&); template void bar() { foo(T()); } int main() { bar(); } ----------------------- The compiler says: g/x> ~/bin/gcc-3.4-pre/bin/c++ -c x.cc x.cc: In instantiation of `X': 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/