Skip to content

Commit

Permalink
[clang][Sema] Restore switch-default.cpp test case
Browse files Browse the repository at this point in the history
This test case exists upstream currently. It was deleted by
mistake when reapplying the patch:
 [clang][Sema] Add -Wswitch-default warning option (llvm#73077)

The test case had been added upstream for a subsequent patch
 [Clang][Sema] Fix Wswitch-default bad warning in template (llvm#76007)

Change-Id: I94fdbe2daa4703166e0d7fc00a3a4d08f98ae410
  • Loading branch information
bcahoon authored and ronlieb committed Jan 12, 2024
1 parent f177937 commit efd092b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions clang/test/Sema/switch-default.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}}
}

0 comments on commit efd092b

Please sign in to comment.