(AST) how to determine if a reference can be replaced with a reference to const?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

(AST) how to determine if a reference can be replaced with a reference to const?

suyash singh via cfe-dev
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

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev