MantisBT - Open CASCADE
View Issue Details
0008239Open CASCADE[OCCT] OCCT:Foundation Classespublic2005-02-22 10:172019-08-17 12:32
stv 
bugmaster 
normaltrivial 
verifiedfixed 
Windows NT
 
[OCCT] 7.4.0* 
Not required
0008239: Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
If custom application uses the OCC and other 3rd party library (for example VTK
or Qt) based on ANSI streams then compiler fails during determination stream
symbols: istream, ostream, ... (compiler error C2872). Directive "using
namespace std" export the all symbol from std namespace into global scope.
Possible solution is not to use directive "using namespace std", but explicitly
specify STL stream symbols (std::ostream) and define preprocessor directive as
namespace prefix name for it.

Enclosed archive (OCC_Streams.tgz) contains example which illustrate proposed
solution with preprocessor directive OCC_STREAM_STD.

Do not hestitate to contact me.

Regards,
STV
Not required
No tags attached.
related to 0005531acknowledged imv Foundation classes - it is impossible avoid "using namespace std" directive when use OCC 
related to 0030895verified bugmaster Coding Rules - specify std namespace explicitly for std::cout and streams 
tgz OCC_Streams.tgz (10,240) 2005-02-22 08:17
https://tracker.dev.opencascade.org/
tgz Sun_Forte_log.tgz (6,415) 2005-02-22 12:23
https://tracker.dev.opencascade.org/
cxx CompilationErrorFixer.cxx (16,590) 2019-08-02 13:51
https://tracker.dev.opencascade.org/
txt compilation_error_replacement_rules.txt (442) 2019-08-02 13:52
https://tracker.dev.opencascade.org/
Issue History
2005-02-22 10:19bugmasterAssigned Tobugmaster => imv
2005-02-22 10:19bugmasterStatusnew => assigned
2005-02-22 14:24bugmasterAssigned Toimv => stv
2007-07-06 18:22abvAssigned Tostv => abv
2011-08-02 11:23bugmasterCategoryOCCT:FDC => OCCT:Foundation Classes
2012-01-19 14:38atpFixed in VersionEMPTY =>
2012-01-19 14:38atpDescription Updatedbug_revision_view_page.php?rev_id=3148#r3148
2014-04-04 06:50abvNote Added: 0028666
2014-09-12 14:29abvTarget Version => 7.1.0
2016-11-01 06:21abvTarget Version7.1.0 => 7.2.0
2017-08-15 12:49abvTarget Version7.2.0 => Unscheduled
2019-07-18 18:55kgvAssigned Toabv => tizmaylo
2019-07-18 18:55kgvTarget VersionUnscheduled => 7.5.0
2019-07-18 18:56kgvRelationship addedrelated to 0005531
2019-07-21 12:23tizmayloSummaryDirective "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries => Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
2019-07-26 10:33gitNote Added: 0085885
2019-07-26 10:33gitNote Added: 0085886
2019-07-26 15:46gitNote Added: 0085897
2019-07-26 15:46gitNote Added: 0085898
2019-07-26 16:35gitNote Added: 0085900
2019-07-26 16:36gitNote Added: 0085901
2019-07-26 17:06gitNote Added: 0085903
2019-07-26 17:06gitNote Added: 0085904
2019-07-26 17:39gitNote Added: 0085907
2019-07-26 17:39gitNote Added: 0085908
2019-07-26 21:51gitNote Added: 0085911
2019-07-26 21:51gitNote Added: 0085912
2019-07-29 09:28gitNote Added: 0085923
2019-07-29 09:28gitNote Added: 0085924
2019-07-29 09:59gitNote Added: 0085925
2019-07-29 12:00gitNote Added: 0085935
2019-08-02 10:35gitNote Added: 0085981
2019-08-02 10:36gitNote Added: 0085982
2019-08-02 13:51tizmayloFile Added: CompilationErrorFixer.cxx
2019-08-02 13:52tizmayloFile Added: compilation_error_replacement_rules.txt
2019-08-02 16:20tizmayloNote Added: 0086000
2019-08-02 16:27tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21561
2019-08-02 16:30tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21562
2019-08-02 16:33tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21563
2019-08-02 16:34tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21564
2019-08-02 16:35tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21565
2019-08-02 16:38tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21566
2019-08-02 16:39tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21567
2019-08-02 16:41tizmayloNote Edited: 0086000bug_revision_view_page.php?bugnote_id=86000#r21568
2019-08-02 16:41tizmayloAssigned Totizmaylo => kgv
2019-08-02 16:41tizmayloStatusassigned => resolved
2019-08-02 16:41tizmayloSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=21570#r21570
2019-08-13 10:57kgvRelationship addedrelated to 0030895
2019-08-13 11:35gitNote Added: 0086220
2019-08-13 13:51kgvNote Added: 0086224
2019-08-13 13:51kgvAssigned Tokgv => bugmaster
2019-08-13 13:51kgvStatusresolved => reviewed
2019-08-13 13:51kgvTarget Version7.5.0 => 7.4.0*
2019-08-13 19:55bugmasterNote Added: 0086235
2019-08-13 19:55bugmasterStatusreviewed => tested
2019-08-13 19:59bugmasterTest case number => Not required
2019-08-17 12:07bugmasterChangeset attached => occt master 7fab82af
2019-08-17 12:07bugmasterStatustested => verified
2019-08-17 12:07bugmasterResolutionopen => fixed
2019-08-17 12:24gitNote Added: 0086300
2019-08-17 12:24gitNote Added: 0086305
2019-08-17 12:24gitNote Added: 0086306

Notes
(0028666)
abv   
2014-04-04 06:50   
Currently we have a set of uses statements for a set of symbols from std namespace (mostly streams) in Standard_Stream.hxx. This can still cause incompatibilities, thus it might be reasonable to remove these, adding prefix std:: explicitly to all references to these symbols in OCCT code.
(0085885)
git   
2019-07-26 10:33   
Branch CR8239 has been created by tizmaylo.

SHA-1: 9866caf30c80ffb80bcac7cbe0d6a3c487460ea3


Detailed log of new commits:

Author: tiv
Date: Fri Jul 26 09:42:14 2019 +0300

(0085886)
git   
2019-07-26 10:33   
Branch CR8239_1 has been created by tizmaylo.

SHA-1: 3fbb700f53cf4593254a2de3f72bf14a3700ec36


Detailed log of new commits:

Author: tiv
Date: Fri Jul 26 10:30:33 2019 +0300

    0008239: Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
    
    "using namespace" directives are removed from some places.
    Last entries of "using std::" are also removed.
(0085897)
git   
2019-07-26 15:46   
Branch CR8239 has been updated by tizmaylo.

SHA-1: 7542fcc6b4eb399c2bd3487d0929ea185d903eb9


Detailed log of new commits:

Author: tiv
Date: Fri Jul 26 15:35:06 2019 +0300

(0085898)
git   
2019-07-26 15:46   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 5cab22b700882c55c07bbfdb899f066d0ee6edd0
(0085900)
git   
2019-07-26 16:35   
Branch CR8239 has been updated by tizmaylo.

SHA-1: 93c0f52728f5ab80fe048994aaa7a11a5c82e4c7


Detailed log of new commits:

Author: tiv
Date: Fri Jul 26 16:29:19 2019 +0300

(0085901)
git   
2019-07-26 16:36   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 70905c20fdbc6197a1b0684156b450bf524cb2ea
(0085903)
git   
2019-07-26 17:06   
Branch CR8239 has been updated forcibly by tizmaylo.

SHA-1: 7d74cdfcf2184054163b4c331e9ce4135122c1e6
(0085904)
git   
2019-07-26 17:06   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 8204c225d5b6d3566bbb74d98679bb97ddad63bf
(0085907)
git   
2019-07-26 17:39   
Branch CR8239 has been updated by tizmaylo.

SHA-1: 1875e1ba1433a699a16e25cb50e60ccd182bf55d


Detailed log of new commits:

Author: tiv
Date: Fri Jul 26 17:34:43 2019 +0300

(0085908)
git   
2019-07-26 17:39   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: e1503097c777d88c47222e2b89cc298ae72acd9b
(0085911)
git   
2019-07-26 21:51   
Branch CR8239 has been updated by tizmaylo.

SHA-1: 9dab76078003ed65a1a87a6253d9fd921901ca2d


Detailed log of new commits:

Author: tiv
Date: Fri Jul 26 18:42:27 2019 +0300

    # std:: prefixes are added in the right places in samples.

(0085912)
git   
2019-07-26 21:51   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: abb154e25cf8f77735df436c343d8468836f1f35
(0085923)
git   
2019-07-29 09:28   
Branch CR8239 has been updated forcibly by tizmaylo.

SHA-1: 2b1ad608a172e016760a56cc700e91bae52979a3
(0085924)
git   
2019-07-29 09:28   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 95a1d0597087e7346c3511d4b20b3d4112914e47
(0085925)
git   
2019-07-29 09:59   
Branch CR8239_1 has been deleted by inv.

SHA-1: 95a1d0597087e7346c3511d4b20b3d4112914e47
(0085935)
git   
2019-07-29 12:00   
Branch CR8239_1 has been created by tizmaylo.

SHA-1: 66a879e19331a4fcde9d68df0e6a9d744c2075cd


Detailed log of new commits:

Author: tiv
Date: Mon Jul 29 11:58:08 2019 +0300

    0008239: Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
    
    "using namespace" directives are removed from some places.
    Last entries of "using std::" are also removed.
    "endl" manipulator for Message_Messenger is renamed to "Message_EndLine".
(0085981)
git   
2019-08-02 10:35   
Branch CR8239 has been updated forcibly by tizmaylo.

SHA-1: 5b4b047b7110f4f164c2709af69251d29ad31315
(0085982)
git   
2019-08-02 10:36   
Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: d5dcd46f9a92d43059b1aa70e64b0788997c9da8
(0086000)
tizmaylo   
2019-08-02 16:20   
(edited on: 2019-08-02 16:41)
Patch is ready for review: http://jenkins-test-12.nnov.opencascade.com:8080/view/CR8239-master-TIV/view/ALL/ [^]

Main OCCT branch: CR8239
OCCT branch with squashed commits: CR8239_1

Main branch in OCCT Products: CR8239
OCCT Products branch with squashed commits: CR8239_1

Some comments on this patch:

Most of the changes are related to the removing of the last entries of using std:: from the header file Standard_Stream.hxx. There were the following names of the standard library objects:
  • istream
  • ostream
  • ifstream
  • ofstream
  • fstream
  • filebuf
  • streambuf
  • streampos
  • ios
  • cout
  • cerr
  • cin
  • endl
  • ends
  • flush
  • setw
  • setprecision
  • hex
  • dec

The corresponding changes in other source files consist of adding std:: prefixes to these names. These changes were done mostly via the following and some other regular expressions:
  • dec, hex, ends, flush
    Find what:
    (?<prefix>\<\<[\n\r\s]*)(?<body>dec|hex|ends|flush)\b(?<postfix>[\n\r\s]*(\<\<|;))
    Replace with:
    ${prefix}std::${body}
  • setw, setprecision
    Find what:
    (?<prefix>\<\<[\n\r\s]*)(?<body>setw|setprecision)(?<postfix>[\n\r\s]*\()
    Replace with:
    ${prefix}std::${body}${postfix}
  • cin
    Find what:
    (?<!\b[\n\r\s]*::[\n\r\s]*)\bcin(?<postfix>[\n\r\s]*(\>\>|\.))
    Replace with:
    std::cin${postfix}
  • ios
    Find what:
    (?<!\b[\n\r\s]*::[\n\r\s]*)\bios(?<postfix>[\n\r\s]*::)
    Replace with:
    std::ios${postfix}
  • filebuf, streambuf, streampos, ifstream, ofstream
    Find what:
    (?<!\b[\n\r\s]*::[\n\r\s]*)\b(?<body>filebuf|streambuf|streampos|ifstream|ofstream)\b
    Replace with:
    std::${body}
  • istream, ostream, fstream
    Find what:
    (?<!(\b[\n\r\s]*::[\n\r\s]*)|(#\s*include\s*<))\b(?<body>istream|ostream|fstream)\b
    Replace with:
    std::${body}
  • cout, cerr
    Find what:
    (?<!\b[\n\r\s]*\:\:[\n\r\s]*)\b(?<body>cout|cerr)(?<postfix>[\n\r\s]*(\<\<|\.))
    Replace with:
    std::${body}${postfix}
  • endl
    Find what:
    (?<prefix>\<\<[\n\r\s]*)endl\b(?<postfix>[\n\r\s]*(\<\<|;))
    Replace with:
    ${prefix}std::endl${postfix}

Some of changes were done via the specially created compilation error fixer (its source code written in C++17 is attached, look at the file CompilationErrorFixer.cxx, https://tracker.dev.opencascade.org/file_download.php?file_id=13678&type=bug [^]). This program parses a build output of Microsoft Visual C++ compiler and tries to fix found compilation errors following the user-defined replacement rules. An example of the file containing such rules is attached (compilation_error_replacement_rules.txt, https://tracker.dev.opencascade.org/file_download.php?file_id=13679&type=bug [^]). An example of a command line to start compilation error fixer application:
CompilationErrorFixer.exe compilation_error_replacement_rules.txt build_output.txt

The compilation error fixer was mostly used to rename the manipulator endl (defined in Message_Messenger.hxx) used with Message_Messenger class (there were about 2,000 places in the source files where this manipulator was used).

The total number of the files that were changed in OCCT: 961.

(0086220)
git   
2019-08-13 11:35   
Branch CR08239_2 has been created by kgv.

SHA-1: 0631b8c48286d62066db409c2027d265de86d0fe


Detailed log of new commits:

Author: kgv
Date: Tue Aug 13 11:33:20 2019 +0300

    0008239: Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
    
    Standard_Stream.hxx no more adds "using std::" entities.
(0086224)
kgv   
2019-08-13 13:51   
Please raise the patch (CR08239_2 in OCCT and CR30895 from Products from another issue).

http://jenkins-test-12.nnov.opencascade.com:8080/view/CR08239_2-CR30895-KGV/ [^]
(0086235)
bugmaster   
2019-08-13 19:55   
Combination -
OCCT branch : CR08239_2
master SHA - 0631b8c48286d62066db409c2027d265de86d0fe
5f5b1aed1c6e139bbd34314eca77ae7abcd8895c
Products branch : CR30895 SHA - 6c5e84c652ce1299c2e1c3b2eff1a35443a236a9
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 16243.920000000046 / 16274.830000000024 [-0.19%]
Products
Total CPU difference: 10479.200000000044 / 10475.390000000047 [+0.04%]
Windows-64-VC14:
OCCT
Total CPU difference: 17671.03125 / 17627.84375 [+0.24%]
Products
Total CPU difference: 12057.671875 / 11990.921875 [+0.56%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
(0086300)
git   
2019-08-17 12:24   
Branch CR08239_2 has been deleted by inv.

SHA-1: 0631b8c48286d62066db409c2027d265de86d0fe
(0086305)
git   
2019-08-17 12:24   
Branch CR8239_1 has been deleted by inv.

SHA-1: d5dcd46f9a92d43059b1aa70e64b0788997c9da8
(0086306)
git   
2019-08-17 12:24   
Branch CR8239 has been deleted by inv.

SHA-1: 5b4b047b7110f4f164c2709af69251d29ad31315