llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-format] Incorrect space for "delete[] *x"

Open zzyyyl opened this issue 4 years ago • 5 comments

Versions: 14 and main

Input

void f() {
  char *x[1] = {new char[10]};
  delete[] *x;
}

Output

void f() {
  char *x[1] = {new char[10]};
  delete[] * x;
}

Expect

same as input

zzyyyl avatar Aug 29 '22 06:08 zzyyyl

@llvm/issue-subscribers-clang-format

llvmbot avatar Aug 29 '22 14:08 llvmbot

Revision: https://reviews.llvm.org/D132911

jackhong12 avatar Aug 30 '22 06:08 jackhong12

@llvm/issue-subscribers-clang-format

llvmbot avatar Aug 30 '22 06:08 llvmbot

@jackhong12 It's still incorrect when --style="{PointerAlignment: Left}"

delete[] *x; -> delete[]* x; delete[] *(x); -> delete[]*(x);

Perhaps the pointer here should be annotated as UnaryOperator?

zzyyyl avatar Aug 30 '22 07:08 zzyyyl

@zzyyyl Thanks for reminding me! You are right. The * token here should be UnaryOperator.

I think the configuration, --style="{PointerAlignment: Left}", will not change the alignment of the * token here. So, the result should be: echo "delete[] *(x);" | clang-format --style="{PointerAlignment: Left}" -> delete[] *(x); echo "delete[] *x;" | clang-format --style="{PointerAlignment: Left}" -> delete[] *x;

jackhong12 avatar Aug 30 '22 07:08 jackhong12