View Issue Details

IDProjectCategoryView StatusLast Update
0008239Open CASCADEOCCT:Foundation Classespublic2019-08-17 12:32
Reporterstv Assigned Tobugmaster  
PrioritynormalSeveritytrivial 
Status closedResolutionfixed 
OSWindows NT 
Target Version7.4.0Fixed in Version7.4.0 
Summary0008239: Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
DescriptionIf 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
Steps To ReproduceNot required
TagsNo tags attached.
Test case numberNot required

Attached Files

  • OCC_Streams.tgz (10,240 bytes)
  • Sun_Forte_log.tgz (6,415 bytes)
  • CompilationErrorFixer.cxx (16,590 bytes)
  • compilation_error_replacement_rules.txt (442 bytes)

Relationships

related to 0005531 closedtizmaylo Foundation classes - it is impossible avoid "using namespace std" directive when use OCC 
related to 0030895 closedbugmaster Coding Rules - specify std namespace explicitly for std::cout and streams 

Activities

2005-02-22 08:17

 

OCC_Streams.tgz (10,240 bytes)

2005-02-22 12:23

 

Sun_Forte_log.tgz (6,415 bytes)

abv

2014-04-04 06:50

manager   ~0028666

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.

git

2019-07-26 10:33

administrator   ~0085885

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

git

2019-07-26 10:33

administrator   ~0085886

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.

git

2019-07-26 15:46

administrator   ~0085897

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

git

2019-07-26 15:46

administrator   ~0085898

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 5cab22b700882c55c07bbfdb899f066d0ee6edd0

git

2019-07-26 16:35

administrator   ~0085900

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

git

2019-07-26 16:36

administrator   ~0085901

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 70905c20fdbc6197a1b0684156b450bf524cb2ea

git

2019-07-26 17:06

administrator   ~0085903

Branch CR8239 has been updated forcibly by tizmaylo.

SHA-1: 7d74cdfcf2184054163b4c331e9ce4135122c1e6

git

2019-07-26 17:06

administrator   ~0085904

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 8204c225d5b6d3566bbb74d98679bb97ddad63bf

git

2019-07-26 17:39

administrator   ~0085907

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

git

2019-07-26 17:39

administrator   ~0085908

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: e1503097c777d88c47222e2b89cc298ae72acd9b

git

2019-07-26 21:51

administrator   ~0085911

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.

git

2019-07-26 21:51

administrator   ~0085912

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: abb154e25cf8f77735df436c343d8468836f1f35

git

2019-07-29 09:28

administrator   ~0085923

Branch CR8239 has been updated forcibly by tizmaylo.

SHA-1: 2b1ad608a172e016760a56cc700e91bae52979a3

git

2019-07-29 09:28

administrator   ~0085924

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: 95a1d0597087e7346c3511d4b20b3d4112914e47

git

2019-07-29 09:59

administrator   ~0085925

Branch CR8239_1 has been deleted by inv.

SHA-1: 95a1d0597087e7346c3511d4b20b3d4112914e47

git

2019-07-29 12:00

administrator   ~0085935

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".

git

2019-08-02 10:35

administrator   ~0085981

Branch CR8239 has been updated forcibly by tizmaylo.

SHA-1: 5b4b047b7110f4f164c2709af69251d29ad31315

git

2019-08-02 10:36

administrator   ~0085982

Branch CR8239_1 has been updated forcibly by tizmaylo.

SHA-1: d5dcd46f9a92d43059b1aa70e64b0788997c9da8

tizmaylo

2019-08-02 13:51

developer  

CompilationErrorFixer.cxx (16,590 bytes)

tizmaylo

2019-08-02 13:52

developer  

compilation_error_replacement_rules.txt (442 bytes)

tizmaylo

2019-08-02 16:20

developer   ~0086000

Last edited: 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.

git

2019-08-13 11:35

administrator   ~0086220

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.

kgv

2019-08-13 13:51

developer   ~0086224

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/

bugmaster

2019-08-13 19:55

administrator   ~0086235

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

git

2019-08-17 12:24

administrator   ~0086300

Branch CR08239_2 has been deleted by inv.

SHA-1: 0631b8c48286d62066db409c2027d265de86d0fe

git

2019-08-17 12:24

administrator   ~0086305

Branch CR8239_1 has been deleted by inv.

SHA-1: d5dcd46f9a92d43059b1aa70e64b0788997c9da8

git

2019-08-17 12:24

administrator   ~0086306

Branch CR8239 has been deleted by inv.

SHA-1: 5b4b047b7110f4f164c2709af69251d29ad31315

Related Changesets

occt: master 7fab82af

2019-08-13 08:33:20

kgv


Committer: bugmaster Details Diff
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.
Affected Issues
0008239
mod - dox/dev_guides/upgrade/upgrade.md Diff File
mod - src/Message/Message_Messenger.hxx Diff File
mod - src/Standard/Standard_Stream.hxx Diff File

Issue History

Date Modified Username Field Change
2005-02-22 10:19 bugmaster Assigned To bugmaster => imv
2005-02-22 10:19 bugmaster Status new => assigned
2005-02-22 14:24 bugmaster Assigned To imv => stv
2007-07-06 18:22 abv Assigned To stv => abv
2011-08-02 11:23 bugmaster Category OCCT:FDC => OCCT:Foundation Classes
2012-01-19 14:38 atp Fixed in Version EMPTY =>
2012-01-19 14:38 atp Description Updated
2014-04-04 06:50 abv Note Added: 0028666
2014-09-12 14:29 abv Target Version => 7.1.0
2016-11-01 06:21 abv Target Version 7.1.0 => 7.2.0
2017-08-15 12:49 abv Target Version 7.2.0 => Unscheduled
2019-07-18 18:55 kgv Assigned To abv => tizmaylo
2019-07-18 18:55 kgv Target Version Unscheduled => 7.5.0
2019-07-18 18:56 kgv Relationship added related to 0005531
2019-07-21 12:23 tizmaylo Summary Directive "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:33 git Note Added: 0085885
2019-07-26 10:33 git Note Added: 0085886
2019-07-26 15:46 git Note Added: 0085897
2019-07-26 15:46 git Note Added: 0085898
2019-07-26 16:35 git Note Added: 0085900
2019-07-26 16:36 git Note Added: 0085901
2019-07-26 17:06 git Note Added: 0085903
2019-07-26 17:06 git Note Added: 0085904
2019-07-26 17:39 git Note Added: 0085907
2019-07-26 17:39 git Note Added: 0085908
2019-07-26 21:51 git Note Added: 0085911
2019-07-26 21:51 git Note Added: 0085912
2019-07-29 09:28 git Note Added: 0085923
2019-07-29 09:28 git Note Added: 0085924
2019-07-29 09:59 git Note Added: 0085925
2019-07-29 12:00 git Note Added: 0085935
2019-08-02 10:35 git Note Added: 0085981
2019-08-02 10:36 git Note Added: 0085982
2019-08-02 13:51 tizmaylo File Added: CompilationErrorFixer.cxx
2019-08-02 13:52 tizmaylo File Added: compilation_error_replacement_rules.txt
2019-08-02 16:20 tizmaylo Note Added: 0086000
2019-08-02 16:27 tizmaylo Note Edited: 0086000
2019-08-02 16:30 tizmaylo Note Edited: 0086000
2019-08-02 16:33 tizmaylo Note Edited: 0086000
2019-08-02 16:34 tizmaylo Note Edited: 0086000
2019-08-02 16:35 tizmaylo Note Edited: 0086000
2019-08-02 16:38 tizmaylo Note Edited: 0086000
2019-08-02 16:39 tizmaylo Note Edited: 0086000
2019-08-02 16:41 tizmaylo Note Edited: 0086000
2019-08-02 16:41 tizmaylo Assigned To tizmaylo => kgv
2019-08-02 16:41 tizmaylo Status assigned => resolved
2019-08-02 16:41 tizmaylo Steps to Reproduce Updated
2019-08-13 10:57 kgv Relationship added related to 0030895
2019-08-13 11:35 git Note Added: 0086220
2019-08-13 13:51 kgv Note Added: 0086224
2019-08-13 13:51 kgv Assigned To kgv => bugmaster
2019-08-13 13:51 kgv Status resolved => reviewed
2019-08-13 13:51 kgv Target Version 7.5.0 => 7.4.0
2019-08-13 19:55 bugmaster Note Added: 0086235
2019-08-13 19:55 bugmaster Status reviewed => tested
2019-08-13 19:59 bugmaster Test case number => Not required
2019-08-17 12:07 bugmaster Changeset attached => occt master 7fab82af
2019-08-17 12:07 bugmaster Status tested => verified
2019-08-17 12:07 bugmaster Resolution open => fixed
2019-08-17 12:24 git Note Added: 0086300
2019-08-17 12:24 git Note Added: 0086305
2019-08-17 12:24 git Note Added: 0086306