Clang Const合格的C ++方法 [英] Clang Const Qualified C++ Method

查看:211
本文介绍了Clang Const合格的C ++方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试一个c ++方法是否在const中限定为const?



例如:

  class Inner {
public:
int i;
Inner();
float inner_method()const;
};

我使用clang-c库,我已经尝试使用 clang_isConstQualifiedType inner_method 节点上。



我不介意如果答案使用clang c ++头文件。解决方案

在C ++接口中,检查方法是使用 CXXMethodDecl :: getTypeQualifiers(),或使用 FunctionProtoType :: getTypeQuals()(取决于你是否有声明或类型)。 Qualifiers :: Const 位指示方法(或方法类型)是否为const。



在libclang C API,这个信息似乎只用于实现 getCursorUSR ,其结果不打算被解析,所以使用C ++ API或提交补丁添加此功能到C API是最好的选择。


How would I test if a c++ method is const qualified in clang?

For example::

class Inner{
public:
    int i;
    Inner();
    float inner_method() const;
};

I am using the clang-c library and I have tried using clang_isConstQualifiedType on the inner_method node. however this returns false.

I don't mind if the answer uses the clang c++ headers.

解决方案

In the C++ interface, the way to check this is using CXXMethodDecl::getTypeQualifiers(), or using FunctionProtoType::getTypeQuals() (depending on whether you have the declaration or the type). The Qualifiers::Const bit indicates whether the method (or method type) is const.

In the libclang C API, this information seems to only be used in the implementation of getCursorUSR, whose result is not intended to be parsed, so using the C++ API or submitting a patch to add this functionality to the C API are the best options.

这篇关于Clang Const合格的C ++方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆