This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Sema] Fix Wswitch-default bad warning in template (#76007)
llvm/llvm-project#73077 added -Wswitch-default diagnostic but it produced false positives in templates. This PR will address that. llvm/llvm-project#75943
- Loading branch information
Showing
3 changed files
with
57 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
} | ||
|