Opened 8 years ago
Closed 7 years ago
#10975 closed Bugs (fixed)
The name exception is ambiguous, exception and std::exception.
Reported by: | Owned by: | Joel de Guzman | |
---|---|---|---|
Milestone: | To Be Determined | Component: | spirit |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description
- Description of the failure.
On Solaris 11.2 Oracle Studio 12.4 C++ compiler under -std=c++11 option produces the following error messages for libs/spirit/classic/test/match_tests.cpp test.
"/usr/include/math.h", line 215: Error: The name exception is ambiguous, exception and std::exception. "/usr/include/math.h", line 215: Error: The name exception is ambiguous, exception and std::exception. ".../boost/exception/exception.hpp", line 140: Error: The name exception is ambiguous, exception and std::exception.
and actually it produces similar error messages for small test like this:
namespace boost {
class exception;
} using namespace boost; #include <algorithm>
or like this:
class exception; using namespace std; #include <algorithm>
Note that in the original boost harness "class exception;" can be found inside: boost/exception/exception.hpp
- Cause of the failure.
This is a C++ vs Unix or Boost vs Unix issue.
Standard Unix requires "struct exception" in the global namespace when <math.h> is included. This conflicts with std::exception or boost::exception, but only when there are using-declarations or using-directives that bring std::exception or boost::exception into the global namespace.
When <math.h> is included, user code must avoid all of the following at file scope (in the global namespace): using namespace std; using namespace boost; using std::exception; using boost::exception;
- Possible Solution.
- Remove line:
using namespace std;
- Replace all 'cout' invocations with 'std::cout'
Change History (4)
comment:1 by , 8 years ago
Component: | Regression Testing → spirit |
---|---|
Owner: | changed from | to
comment:2 by , 8 years ago
It would be good if you can provide a pull request for this: https://github.com/boostorg/spirit. Thanks!
comment:4 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In addition to fixe inside match_tests.cpp described in original filings, 15 more tests from spirit/classic/test directory listed below should be similarly modified. From all of them "using namespace std" should be removed, and std:: prefix should be added to the proper STL functions.
11 tests with require removing "using namespace std" only:
grammar_tests.cpp operators_tests.cpp subrule_tests.cpp
closure_tests.cpp
parametric_tests.cpp
switch_tests_eps_default.cpp
switch_tests_general_def.cpp
switch_tests_single.cpp
switch_tests_wo_default.cpp
switch_tests_single.cpp
loops_tests.cpp
4 tests which require to add std:: prefix:
scanner_tests.cpp : cout, list
primitives_tests.cpp : cout
directives_tests.cpp : cout, endl, string
rule_tests.cpp : cout, endl