[cfe-dev] Is it safe to cast-away constness to use Clang static analysis?

John McCall via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 3 17:20:02 PDT 2017

> On Oct 3, 2017, at 4:51 PM, Roman Popov via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> Yes, this is what I have to do.
> Actually RecursiveASTVisitor does not enforce constness, so probably it is AST matchers that are not consistent with rest of Clang API. 

Clang is unfortunately just inconsistent about it.

The AST is largely immutable by design, and the best solution would probably be to adopt what LLVM did to Type and just mass-refactor code to stop passing around const pointers at all.


> -Roman
> 2017-10-03 12:49 GMT-07:00 Jonas Toth <jonas.toth at gmail.com <mailto:jonas.toth at gmail.com>>:
> Hi,
> you can try `const_cast` as first try to do it.
> Jonas
> Am 03.10.2017 um 21:31 schrieb Roman Popov via cfe-dev:
>> Hello,
>> I'm writing a code refactoring tool that needs some static analysis capabilities.
>> I've noticed that AST Matchers return const AST nodes, but static analysis sometimes wants to consume non-const pointers.
>> For example to build call graph I need to pass non-const pointer:
>>  CallGraph::addToCallGraph(Decl *D)
>> So does static analysis modifies AST? Or it's just a bug in method signature?
>> Thanks,
>> Roman
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171003/10212117/attachment.html>

More information about the cfe-dev mailing list