File: error_macro_unreachable.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (63 lines) | stat: -rw-r--r-- 1,281 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <Halide.h>

#include <cstdio>
#include <string>

enum class Example {
    A,
    B,
    C
};

// If the error macros are implemented correctly, it should be possible
// to determine that example_to_string returns a value in all non-error
// cases.
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic error "-Wreturn-type"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wreturn-type"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(error : 4715)
#endif

std::string example_to_string1(const Example e) {
    switch (e) {
    case Example::A:
        return "A";
    case Example::B:
        return "B";
        // Oops, missing Example::C.
    default:
        break;
    }
    internal_error << "Unreachable\n";
}

std::string example_to_string2(const Example e) {
    switch (e) {
    case Example::A:
        return "A";
    case Example::B:
        return "B";
        // Oops, missing Example::C.
    default:
        break;
    }
    internal_assert(false) << "Unreachable\n";
}

#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif

int main() {
    printf("Success!\n");
    return 0;
}