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 (fwd)
Date: Fri, 25 Apr 2003 19:16:00 -0000	[thread overview]
Message-ID: <20030425191601.10112.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: 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 <foster@diskworld.wharton.upenn.edu>
 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 <utility>
 
 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<T,T> pair;
 };
 
 namespace apl
 {  
   template <class T>
   typename flag_error<T>::pair                                          // ** 2 **
   operator-(const T& ,  const T& )
   {
   }
 } 
 
 std::pair<Iterator,Iterator>
 pair_iterator_constructor()
 {
 };
 
 template<class T>
 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());
 }
 
 
 
 


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

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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