public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10437: "using namespace" at global scope creates incorrect code (fwd)
@ 2003-04-25 19:16 Wolfgang Bangerth
0 siblings, 0 replies; only message in thread
From: Wolfgang Bangerth @ 2003-04-25 19:16 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
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());
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-04-25 19:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-25 19:16 c++/10437: "using namespace" at global scope creates incorrect code (fwd) 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).