Opened 8 years ago

Closed 7 years ago

#10975 closed Bugs (fixed)

The name exception is ambiguous, exception and std::exception.

Reported by: Sergey.Sprogis@… Owned by: Joel de Guzman
Milestone: To Be Determined Component: spirit
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

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

  1. 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;

  1. Possible Solution.
  • Remove line:

using namespace std;

  • Replace all 'cout' invocations with 'std::cout'

Change History (4)

comment:1 by Sergey.Sprogis@…, 8 years ago

Component: Regression Testingspirit
Owner: changed from René Rivera to Joel de Guzman

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

comment:2 by Joel de Guzman, 8 years ago

It would be good if you can provide a pull request for this: https://github.com/boostorg/spirit. Thanks!

comment:3 by Aparna Kumta <aparna.kumta@…>, 7 years ago

comment:4 by Joel de Guzman, 7 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.