<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - ASTContext::getRawCommentForDeclNoCache() ignores enum value decls, returns wrong comment"
href="https://bugs.llvm.org/show_bug.cgi?id=39757">39757</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ASTContext::getRawCommentForDeclNoCache() ignores enum value decls, returns wrong comment
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>djeedai@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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
{
/// <a href="show_bug.cgi?id=39757#c1">Comment1</a>
One = 1,
Two = 2, /// <a href="show_bug.cgi?id=39757#c2">Comment2</a>
Three = 3,
Four = 4,
Five = 5,
};
Here the enum value decl "One" gets "<a href="show_bug.cgi?id=39757#c1">Comment1</a>" as expected, but for all other 4
decls getRawCommentForDeclNoCache() returns "<a href="show_bug.cgi?id=39757#c2">Comment2</a>", 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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>