================
Comment at: clang-tidy/misc/BracesAroundStatementsCheck.cpp:96
@@ +95,3 @@
+    SourceLocation StartLoc =
+        backwardSkipWhitespacesAndComments(
+            *Result.SourceManager, Result.Context, 
WS->getBody()->getLocStart())
----------------
curdeius wrote:
> alexfh wrote:
> > I think, RParenLoc should be stored inside WhileStmt and IfStmt, then this 
> > code will be much easier. This doesn't have to be in this patch, but please 
> > add a FIXME.
> Ok for a FIXME.
> I'd prefer creating a new patch for this, as this can have wider 
> repercussions, not only on clang-tidy.
Sure. I've prepared D5528 to address this. Not sure though, whether we'll go 
this way or not.

================
Comment at: test/clang-tidy/misc-braces-around-statements.cpp:147
@@ +146,3 @@
+  // CHECK-FIXES: if (cond("ifif2")) {
+  // CHECK-FIXES: /*comment*/ ;}} // comment
+
----------------
curdeius wrote:
> alexfh wrote:
> > This looks slightly wrong to put a closing brace before a trailing comment, 
> > and clang-format won't fix this. I think, the check should try to keep the 
> > trailing comment next to the statement it belongs to. I'm not sure if there 
> > can be a 100% fool-proof solution, but I hope, we can come up with a decent 
> > heuristic.
> > 
> > Assuming the coding style is similar to the one used in LLVM, we could do 
> > the following:
> > 
> >   1. if there's a corresponding "else" or "while", the check should insert 
> > "} " right before that token.
> >   2. if there's a multi-line block comment starting on the same line after 
> > the location we're inserting the closing brace at, or there's a non-comment 
> > token, the check should insert "} " right before that token.
> >   3. otherwise the check should find the end of line (possibly after some 
> > block or line comments) and insert "}\n" right after that EOL. It could 
> > also insert some spaces to make the indentation nice, but this could be 
> > done by clang-format as well.
> > 
> > Do you see any problems with this plan?
> Looks like a plan!
> 1. is trivial (already done), 2. and 3. should be quite easy too.
> In 3. I would leave indentation to clang-format, anyway one should run it 
> after using clang-tidy.
> 
> Is there any easy way of checking if a block-comment spans over multiple 
> lines?
> In 3. I would leave indentation to clang-format, anyway one should run it 
> after using clang-tidy.

Sounds good.

> Is there any easy way of checking if a block-comment spans over multiple 
> lines?

I'd try something like this:

  Lexer::getSourceText(CharSourceRange::getTokenRange(Tok.getLocation(), 
Tok.getLocation()), Result.SourceManager, 
Result.Context->getLangOpts()).find('\n') != StringRef::npos

http://reviews.llvm.org/D5395



_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to