aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Sema/switch-default.cpp
blob: 32d03dae882733426613cbb71dd021e9079a726a (plain)
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
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wswitch-default %s

int f1(int a) {
  switch (a) {                // expected-warning {{'switch' missing 'default' label}}
    case 1: a++; break;
    case 2: a += 2; break;
  }
  return a;
}

int f2(int a) {
  switch (a) {                // no-warning
    default:
      ;
  }
  return a;
}

// Warn even completely covered Enum cases(GCC compatibility).
enum E { A, B };
enum E check_enum(enum E e) {
  switch (e) {                // expected-warning {{'switch' missing 'default' label}}
    case A: break;
    case B: break;
  }
  return e;
}

template<typename Index>
int t1(Index i)
{
  switch (i) {              // expected-warning {{'switch' missing 'default' label}}
    case 0: return 0;
    case 1: return 1;
  }
  return 0;
}

template<typename Index>
int t2(Index i)
{
  switch (i) {            // no-warning
    case 0: return 0;
    case 1: return 1;
    default: return 2;
  }
  return 0;
}

int main() {
  return t1(1);       // expected-note {{in instantiation of function template specialization 't1<int>' requested here}}
}