Bug 1287 - Injecting std:: names into the global namespace
Summary: Injecting std:: names into the global namespace
Status: NEW
Alias: None
Product: ACE
Classification: Unclassified
Component: ACE Core (show other bugs)
Version: 5.2.3
Hardware: All All
: P3 normal
Assignee: DOC Center Support List (internal)
URL:
Depends on: 193
Blocks:
  Show dependency tree
 
Reported: 2002-08-20 10:59 CDT by Nanbor Wang
Modified: 2006-08-16 09:08 CDT (History)
0 users

See Also:


Attachments
Patch against x.2.3 (25.65 KB, patch)
2002-12-03 12:00 CST, Nanbor Wang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nanbor Wang 2002-08-20 10:59:28 CDT
Ken Yarnall <pettice.yarnall@verizon.net> reports this

-------------------------------------------------------------
It's generally considered impolite to inject names into the global
namespace needlessly from a header file via using
directives/declarations.  ACE does this with some names from std::,
if the compiler has a modern standard library --- see the streams.h
and iosfwd.h headers in $ACE_ROOT/ace.

There's no real reason for ACE to do this, and it has some bad
effects; standard library names are "magically" available without
qualification (this behavior mystified some of my students at various
points during a course last semester).

I have a patch to ACE (based on version 5.2.3) that eliminates this
behavior.  Essentially, it deletes the offending sections of
streams.h and iosfwd.h and modifies the definition of the macro
ACE_OSTREAM_TYPE in OS.h to include std:: if appropriate.  It also
builds a similar macro for ACE_OFSTREAM_TYPE since ACE code uses
std::ofstream in places (the Logging stuff, mainly) and cleans up one
or two other spots.  Finally, it conditionally inserts "using
namespace std" at the beginning of the test programs that make
reference to standard names (doing this in such cpp files is harmless
to application code, of course).

The patched library builds cleanly using gcc v3.2 (new library) and
gcc v2.96 (old library) on RedHat 7.3, and the resulting libs pass
some simple tests.  I haven't tried the patched version on other
platforms, but the patch is simple, and I don't see any way for it to
cause trouble elsewhere.

It will require application writers to add namespace directives to
code where they've taken advantage of ACE's current behavior.

Is the ACE group interested in this patch?  I'd be glad to send the
patch file in if it's desired.

---------------------------------------------------------------------
Adding this to ACE to fix the std:: injection is a backward compatibility 
issue. Hence the plan suggested by Dr. Levine, and which was generally accepted 
by everyone was to, is to add a new #define that can be set during compilation 
which prevents injection of std:: to the global namespace. This way we could 
avoid the backward compatibility problem. This needs to be done before x.3 out. 

The other part of this problem is to make sure that we dont inject stuff into 
the global namespace by default. This would be taken up after x.3 is out.
Comment 1 Nanbor Wang 2002-08-28 14:49:26 CDT
Accept for tao-support
Comment 2 Nanbor Wang 2002-12-03 12:00:18 CST
Created attachment 171 [details]
Patch against  x.2.3
Comment 3 Nanbor Wang 2002-12-03 12:01:04 CST
Patch from Ken Yarnall has been attached. If possible we need to get this in 
for 1.3.
Comment 4 Johnny Willemsen 2005-01-02 05:40:21 CST
I will try to handle this asap
Comment 5 Johnny Willemsen 2005-01-09 12:50:44 CST
accept
Comment 6 Johnny Willemsen 2006-08-16 09:08:56 CDT
to pool