[all-commits] [llvm/llvm-project] 5918ef: [clangd] Handle duplicate enum constants in Popula...

Nathan James via All-commits all-commits at lists.llvm.org
Mon Nov 9 04:15:16 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 5918ef8b1aac00af2f8dd8b99f3de7b176463444
      https://github.com/llvm/llvm-project/commit/5918ef8b1aac00af2f8dd8b99f3de7b176463444
  Author: Nathan James <n.james93 at hotmail.co.uk>
  Date:   2020-11-09 (Mon, 09 Nov 2020)

  Changed paths:
    M clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
    M clang-tools-extra/clangd/unittests/TweakTests.cpp
    M llvm/include/llvm/ADT/DenseMapInfo.h

  Log Message:
  -----------
  [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




More information about the All-commits mailing list