Skip to content

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

@krlmlr

Description

@krlmlr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions