[llvm-bugs] [Bug 39757] New: ASTContext::getRawCommentForDeclNoCache() ignores enum value decls, returns wrong comment
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 22 08:49:04 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=39757
Bug ID: 39757
Summary: ASTContext::getRawCommentForDeclNoCache() ignores enum
value decls, returns wrong comment
Product: clang
Version: 6.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: djeedai at gmail.com
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
When using ASTContext::getRawCommentForDeclNoCache() to get the comment
associated with a Decl, the high-level algorithm is as follow:
- Find the location of the Decl,
- Find if a trailing comment follows the Decl, if so return it,
- Otherwise find the previous comment, located before the Decl,
- Check that no other Decl exists between that comment and the target Decl.
The last step is implemented with a fast but brittle string compare:
// There should be no other declarations or preprocessor directives between
// comment and declaration.
if (Text.find_first_of(";{}#@") != StringRef::npos)
return nullptr;
Unfortunately, for enum value decls, the separator is a comma ',' which means
that all the value decls following a comment will return that same comment:
enum class MyEnum
{
/// Comment1
One = 1,
Two = 2, /// Comment2
Three = 3,
Four = 4,
Five = 5,
};
Here the enum value decl "One" gets "Comment1" as expected, but for all other 4
decls getRawCommentForDeclNoCache() returns "Comment2", even though I would
expect only the second value has a comment.
A possible fix is to add the comma ',' to the list of tested characters, though
I am not sure if that can break something else. Any opinion?
Thanks
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181122/4ab52e55/attachment.html>
More information about the llvm-bugs
mailing list