[clang-format] Prevent re-assigning type on finalized tokens (#210763)
Prevents a finalized token inside modifyContext from being reassigned through the setType member function by checking if the token is finalized. This ensures ill-defined code like does not trigger an assertion failure during reformatting. Fixes #210509
This commit is contained in:
parent
f279abcc81
commit
2d0b45bc0a
2 changed files with 3 additions and 1 deletions
|
|
@ -2308,7 +2308,8 @@ private:
|
|||
}
|
||||
if (Previous->opensScope())
|
||||
break;
|
||||
if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
|
||||
if (!Previous->isTypeFinalized() &&
|
||||
Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
|
||||
Previous->isPointerOrReference() && Previous->Previous &&
|
||||
Previous->Previous->isNot(tok::equal)) {
|
||||
Previous->setType(TT_PointerOrReference);
|
||||
|
|
|
|||
|
|
@ -22562,6 +22562,7 @@ TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
|
|||
verifyNoCrash("[[ [a] ]]");
|
||||
verifyNoCrash(
|
||||
"#xxxx??x<xxxxxxx||??x<xxxxxxx and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
verifyNoCrash("a &alias & =");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsTableGenCode) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue