-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang] Repair the function "rParenEndsCast" to make incorrect judgments in template variable cases #120904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Repair the function "rParenEndsCast" to make incorrect judgments in template variable cases #120904
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,8 @@ | |||||||||||
#include "clang/Basic/SourceManager.h" | ||||||||||||
#include "clang/Basic/TokenKinds.h" | ||||||||||||
#include "llvm/ADT/SmallPtrSet.h" | ||||||||||||
#include "llvm/ADT/SmallVector.h" | ||||||||||||
#include "llvm/ADT/StringRef.h" | ||||||||||||
#include "llvm/Support/Debug.h" | ||||||||||||
|
||||||||||||
#define DEBUG_TYPE "format-token-annotator" | ||||||||||||
|
@@ -38,6 +40,10 @@ static bool mustBreakAfterAttributes(const FormatToken &Tok, | |||||||||||
|
||||||||||||
namespace { | ||||||||||||
|
||||||||||||
// TODO: Add new Type modifiers | ||||||||||||
llvm::SmallVector<llvm::StringRef> castIdentifiers{"__type_identity_t", | ||||||||||||
"remove_reference_t"}; | ||||||||||||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||||||||||||
|
||||||||||||
/// Returns \c true if the line starts with a token that can start a statement | ||||||||||||
/// with an initializer. | ||||||||||||
static bool startsWithInitStatement(const AnnotatedLine &Line) { | ||||||||||||
|
@@ -2474,6 +2480,11 @@ class AnnotatingParser { | |||||||||||
Current.getNextNonComment()->isOneOf(tok::comma, tok::r_brace)) { | ||||||||||||
Current.setType(TT_StringInConcatenation); | ||||||||||||
} | ||||||||||||
} else if (Style.isCpp() && Current.is(tok::kw_using)) { | ||||||||||||
if (Current.Next && Current.Next->Next && Current.Next->Next->Next) { | ||||||||||||
if (Current.Next->Next->Next->isTypeName(LangOpts)) | ||||||||||||
Comment on lines
+2483
to
+2485
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this is too simplistic to be very useful. See the general syntax here. Also, this doesn't work at all if the |
||||||||||||
castIdentifiers.push_back(Current.Next->TokenText); | ||||||||||||
} | ||||||||||||
} else if (Current.is(tok::l_paren)) { | ||||||||||||
if (lParenStartsCppCast(Current)) | ||||||||||||
Current.setType(TT_CppCastLParen); | ||||||||||||
|
@@ -2831,8 +2842,21 @@ class AnnotatingParser { | |||||||||||
IsQualifiedPointerOrReference(BeforeRParen, LangOpts); | ||||||||||||
bool ParensCouldEndDecl = | ||||||||||||
AfterRParen->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater); | ||||||||||||
if (ParensAreType && !ParensCouldEndDecl) | ||||||||||||
if (ParensAreType && !ParensCouldEndDecl) { | ||||||||||||
if (BeforeRParen->is(TT_TemplateCloser)) { | ||||||||||||
if (determineUnaryOperatorByUsage(*AfterRParen)) | ||||||||||||
return true; | ||||||||||||
if (AfterRParen->isOneOf(tok::plus, tok::minus, tok::star, tok::exclaim, | ||||||||||||
tok::amp)) { | ||||||||||||
auto *Prev = BeforeRParen->MatchingParen->getPreviousNonComment(); | ||||||||||||
for (auto &name : castIdentifiers) | ||||||||||||
if (Prev->TokenText == name) | ||||||||||||
return true; | ||||||||||||
return false; | ||||||||||||
Comment on lines
+2852
to
+2855
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
} | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
|
||||||||||||
// At this point, we heuristically assume that there are no casts at the | ||||||||||||
// start of the line. We assume that we have found most cases where there | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.