[clangd] Handle duplicate enum constants in PopulateSwitch tweak
authorNathan James <n.james93@hotmail.co.uk>
Mon, 9 Nov 2020 12:14:51 +0000 (12:14 +0000)
committerNathan James <n.james93@hotmail.co.uk>
Mon, 9 Nov 2020 12:14:53 +0000 (12:14 +0000)
commit5918ef8b1aac00af2f8dd8b99f3de7b176463444
treede04459c44e6b0e5d09ebf8f3e62bfcef24e632a
parent57f87977f53fd1c06fee669511520f33cdc85a20
[clangd] Handle duplicate enum constants in PopulateSwitch tweak

If an enum has different names for the same constant, make sure only the first one declared gets added into the switch. Failing to do so results in a compiler error as 2 case labels can't represent the same value.

```
lang=c
enum Numbers{
One,
Un = One,
Two,
Deux = Two,
Three,
Trois = Three
};

// Old behaviour
switch (<Number>) {
  case One:
  case Un:
  case Two:
  case Duex:
  case Three:
  case Trois: break;
}

// New behaviour
switch (<Number>) {
  case One:
  case Two:
  case Three: break;
}
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90555
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
llvm/include/llvm/ADT/DenseMapInfo.h