[cfe-dev] (AST) how to determine if a reference can be replaced with a reference to const?

Nikita Petrenko via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 11 02:45:14 PDT 2020


Suppose that I have some non-const reference ref of type T&. Suppose that I
have some expression, e.g.:
RunFunction(ref.CallSomeMethod())

where overloaded CallSomeMethod has signatures
int& T::CallSomeMethod() &;
const int& T::CallSomeMethod() const&;

What is the best way to determine though AST if the the program would still
compile with the following modification?
RunFunction(static_cast<const T&>(ref).CallSomeMethod())

I'm writing a refactoring tool which rewrites public fields to fields with
getters. The thing is, I have different member functions for const and
mutable access, e.g.:
int& T::MutableField() &;
const int& T::Field() const&;

I would like to be able to distinguish between const/mutable access using
AST.

Best,
Nikita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200311/be3ec0fb/attachment.html>


More information about the cfe-dev mailing list