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

How to teach the compiler that stop() doesn't return? #486

Closed
krlmlr opened this issue Jun 1, 2016 · 2 comments
Closed

How to teach the compiler that stop() doesn't return? #486

krlmlr opened this issue Jun 1, 2016 · 2 comments

Comments

@krlmlr
Copy link
Contributor

@krlmlr krlmlr commented Jun 1, 2016

So that we can write

bool foo(int x) {
  switch (x) {
    case 1: return true;
    case 2: return false;
    default: stop("Don't know this x");
  }
}

without issuing a warning.

There is a "noreturn" attribute for GCC and clang, but there might be other solutions. EDIT: http://stackoverflow.com/a/25408952/946850 is a nice SO answer that features __builtin_unreachable().

Re tidyverse/dplyr#1878 (comment), CC @hadley.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jun 1, 2016

For what it's worth, R defines the NORET macro for handling this as well so we could potentially just use that: https://github.com/wch/r-source/blob/trunk/src/include/R_ext/Error.h#L29-L37

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Jul 20, 2016

We appear to have issues with this per #512.

@krlmlr @kevinushey Can one of you familiar with NORET please check how / why it is defined? I tried adding a simple

#undef NORET

in the file, but no mas. If and when I do replace NORET with /*NORET*/ then I can build on the old platform.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.