From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10127 invoked by alias); 25 Apr 2003 19:16: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 10113 invoked by uid 71); 25 Apr 2003 19:16:01 -0000 Date: Fri, 25 Apr 2003 19:16:00 -0000 Message-ID: <20030425191601.10112.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 (fwd) Reply-To: Wolfgang Bangerth X-SW-Source: 2003-04/txt/msg01122.txt.bz2 List-Id: The following reply was made to PR c++/10437; it has been noted by GNATS. From: Wolfgang Bangerth To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/10437: "using namespace" at global scope creates incorrect code (fwd) Date: Fri, 25 Apr 2003 14:15:09 -0500 (CDT) ---------- Forwarded message ---------- Date: 22 Apr 2003 11:59:01 -0000 From: Dean Foster To: bangerth@ices.utexas.edu Subject: Re: c++/10437: "using namespace" at global scope creates incorrect code I've shortened it down to about 50 lines. (Took several 100 compiles. First to generate the error then move the one line, and confirm the error goes away!) It is cut-and-pasted at the end of this email. There are several lines that turned out to be needed in order for the error to be generated. The line ** 1 ** actually generates the error. The line ** 2 ** calls the error_generator. Line ** 3 ** is where the error is. It shouldn't ever try the apl::operator-() code, but it does if the "using namespace" is outside of the main(). Move line ** 4 ** around to see the most obvious way that this is an error. Thanks for your willingness to be patient. Of course putting "using namespace"'s at global scope is pure evil! We only had it in our test code. later, dean ============================================================================= Dean Foster dean@foster.net Statistics, Wharton, U. Penn 215 898 8233 Philadelphia PA 19104-6340 http://diskworld.wharton.upenn.edu ============================================================================= // $Id: namespace_error.cc,v 4.29 2003/04/22 11:45:10 foster Exp $ #include class Iterator { public: void operator-(Iterator){}; }; template < class T> class flag_error { public: typedef typename T::type_doesnt_exist unused_type; // ** 1 ** typedef std::pair pair; }; namespace apl { template typename flag_error::pair // ** 2 ** operator-(const T& , const T& ) { } } std::pair pair_iterator_constructor() { }; template void foo(T t) { t.first - t.second; // ** 3 ** } // moving ** 4 ** from inside to outside of the main() changes from "legal" to "errors" using namespace apl; // ** 4 ** int main() { foo(pair_iterator_constructor()); }