Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang-format does not recognize rvalue references to array #51562

Open Quuxplusone opened 2 years ago

Quuxplusone commented 2 years ago
Bugzilla Link PR52595
Status CONFIRMED
Importance P enhancement
Reported by Zhihao Yuan (lichray@gmail.com)
Reported on 2021-11-23 21:05:42 -0800
Last modified on 2021-11-24 02:18:16 -0800
Version trunk
Hardware All All
CC djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org, mydeveloperday@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
struct FnArray {
  template <class T, int N>
  constexpr int operator()(T (&)[N]) const { return 0; } // 1

  template <class T, int N>
  constexpr int operator()(T(&&)[N]) const { return 1; } // 2
};

Note that the line // 2 lost the space between T and the open (.
Quuxplusone commented 2 years ago
Simpler failing use case

int operator()(T (&)[N]) { return 0; }
int operator()(T(&&)[N]) { return 1; }
Quuxplusone commented 2 years ago
In the correct case, the & is seen as PointerOrReference

 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=int L=3 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c048fc0 Text='int'
 M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=operator L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c0498a0 Text='operator'
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=OverloadedOperatorLParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=identifier L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c03d6b8 Text='T'
 M=0 C=0 T=FunctionTypeLParen S=1 F=0 B=0 BK=0 P=43 Name=l_paren L=18 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=PointerOrReference S=0 F=0 B=0 BK=0 P=250 Name=amp L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='&'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=68 Name=r_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=ArraySubscriptLSquare S=0 F=0 B=0 BK=0 P=540 Name=l_square L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='['
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=259 Name=identifier L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c03d6e8 Text='N'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=243 Name=r_square L=23 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=']'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=24 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=FunctionLBrace S=1 F=0 B=0 BK=1 P=23 Name=l_brace L=26 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='{'

in the failing case its seen as a UnaryOperator

 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=int L=3 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c048fc0 Text='int'
 M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=operator L=12 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c0498a0 Text='operator'
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=13 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=OverloadedOperator S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=14 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=OverloadedOperatorLParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=identifier L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c03d6b8 Text='T'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=l_paren L=17 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=UnaryOperator S=0 F=0 B=0 BK=0 P=160 Name=ampamp L=19 PPK=2 FakeLParens=0/ FakeRParens=1 II=0x0 Text='&&'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=120 Name=r_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=ArraySubscriptLSquare S=0 F=0 B=0 BK=0 P=540 Name=l_square L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='['
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=259 Name=identifier L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x1b34c03d6e8 Text='N'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=243 Name=r_square L=23 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=']'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=24 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=FunctionLBrace S=1 F=0 B=0 BK=1 P=23 Name=l_brace L=26 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='{'
Quuxplusone commented 2 years ago

Possible fix

https://reviews.llvm.org/D114519