Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turned off exception handling support #50

Closed
Sp3EdeR opened this issue Nov 3, 2016 · 6 comments
Closed

Turned off exception handling support #50

Sp3EdeR opened this issue Nov 3, 2016 · 6 comments
Labels

Comments

@Sp3EdeR
Copy link

Sp3EdeR commented Nov 3, 2016

Hello!
I would like to request support for compilation with exception handling turned off.
This is currently an issue within the "narrow" function, which throws "narrowing_error"-s and results in a compilation error on clang.

../thirdparty/gsl-lite/include/gsl/gsl-lite.h:598:9: error: cannot use 'throw' with exceptions disabled
throw narrowing_error();

I would like to request a configuration similar to the contract violation throw/terminate one.

@martinmoene
Copy link
Collaborator

Would it be ok to switch on the exisiting gsl_CONFIG_CONTRACT_VIOLATION_THROWS_V?

#if gsl_CONFIG_CONTRACT_VIOLATION_THROWS_V
   throw narrowing_error();
#else 
   std::terminate();
#endif

@Sp3EdeR
Copy link
Author

Sp3EdeR commented Nov 3, 2016

Hello!

Yes, that would work fine technically.
I was just thinking that technically these cases were not contract violations. As such I thought maybe a new configuration option was necessary to perhaps completely disable exceptions, which would of course imply said config option, but not the other way around. If this solution is acceptable for you, I'd be happy to get the update. :)

@martinmoene
Copy link
Collaborator

I was just thinking that technically these cases were not contract violations.

That crossed my mind too.

Considering:

  • gsl_CONFIG_NARROW_DISCARD_THROWS / gsl_CONFIG_NARROW_DISCARD_TERMINATES
  • gsl_CONFIG_NARROW_LOSS_THROWS / gsl_CONFIG_NARROW_LOSS_TERMINATES
  • gsl_CONFIG_NARROW_GUARD_THROWS / gsl_CONFIG_NARROW_GUARD_TERMINATES

@Sp3EdeR
Copy link
Author

Sp3EdeR commented Nov 3, 2016

I would personally opt for a generic configuration dealing with whether to throw or terminate.
I imagine most users would not want to customize the behaviour per-feature. It would also possibly increase the configuration options in the future by a large number. This also seems more analoguous with the contract violation configuration, since that can also be used in many features.

I would probably use this or something similar:
gsl_CONFIG_RUNTIME_ERROR_TERMINATES / gsl_CONFIG_RUNTIME_ERROR_THROWS

@viboes
Copy link

viboes commented Nov 3, 2016

We can see it as a contract violation of the function requires that narrow_cast doesn't lost information.

@martinmoene
Copy link
Collaborator

Added in v0.14.0

I've put it under the umbrella of contract violation, at least initially:

  • gsl_CONFIG_CONTRACT_VIOLATION_THROWS
  • gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants