Archived issue #0008239
Foundation Classes - directive "using namespace std" doesn't allow to build application with OCC and other 3rd party libraries
Description
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 (Attachment 1 (TGZ)) contains example which illustrate proposed
solution with preprocessor directive OCC_STREAM_STD.
Do not hestitate to contact me.
[signature removed]
STV
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 (Attachment 1 (TGZ)) contains example which illustrate proposed
solution with preprocessor directive OCC_STREAM_STD.
Do not hestitate to contact me.
[signature removed]
STV
Steps to reproduce
Not required
Public activity
26 archived notes
Participants are labeled by their role within this record.
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.
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 09:42:14 2019 +0300
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 09:42:14 2019 +0300
Branch [archived branch] has been created by Participant.
[revision removed]
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.
[revision removed]
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.
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 15:35:06 2019 +0300
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 15:35:06 2019 +0300
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 16:29:19 2019 +0300
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 16:29:19 2019 +0300
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 17:34:43 2019 +0300
[revision removed]
Detailed log of new commits:
Author: tiv
Date: Fri Jul 26 17:34:43 2019 +0300
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated by Participant.
[revision removed]
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.
[revision removed]
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.
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been created by Participant.
[revision removed]
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".
[revision removed]
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".
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
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:
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:
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, [archived tracker link removed]). 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, [archived tracker link removed]). An example of a command line to start compilation error fixer application:
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.
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, [archived tracker link removed]). 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, [archived tracker link removed]). 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.
Branch [archived branch] has been created by Commenter 3.
[revision removed]
Detailed log of new commits:
Author: Commenter 3
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.
[revision removed]
Detailed log of new commits:
Author: Commenter 3
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.
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/
http://jenkins-test-12.nnov.opencascade.com:8080/view/CR08239_2-CR30895-KGV/
Combination -
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
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
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
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
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Related records