Allow any comment to be a trailing comment when -fparse-all-comments is on.
authorJames Dennett <jdennett@google.com>
Wed, 15 Jul 2015 19:13:39 +0000 (19:13 +0000)
committerJames Dennett <jdennett@google.com>
Wed, 15 Jul 2015 19:13:39 +0000 (19:13 +0000)
commit2def1e8ad6b84d1a8a18de8789093e5faf8d3aed
tree087ef355de6abb8a6ca782b5c5911f7506d1141b
parent525579d41cb7ecdc72418326585adacf88bb5bc2
Allow any comment to be a trailing comment when -fparse-all-comments is on.

This helps with freeform documentation styles, where otherwise code like
  enum class E {
    E1,  // D1
    E2   // D2
  };
would result in D1 being associated with E2. To properly associate E1
with D1 and E2 with D2, this patch allows all raw comments C such that
C.isParseAllComments() to participate in trailing comment checks inside
getRawCommentForDeclNoCache. This takes care of linking the intended
documentation with the intended decls. There remains an issue with code
like:
  foo();  // DN
  int x;
To prevent DN from being associated with x, this patch adds a new test
on preceding-line comments C (where C.isParseAllComments() and also
C's kind is RCK_OrdinaryBCPL or RCK_OrdinaryC) that checks whether C
is the first non-whitespace thing on C's starting line.

Patch from Luke Zarko <zarko@google.com>, D11069 reviewed by rsmith.

llvm-svn: 242317
clang/lib/AST/RawCommentList.cpp
clang/test/Index/parse-all-comments.c