Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用Clang LIB工具扫描C++;在模板化父类中调用本地类的源_C++_Templates_Clang_Libtooling_Local Class - Fatal编程技术网

C++ 使用Clang LIB工具扫描C++;在模板化父类中调用本地类的源

C++ 使用Clang LIB工具扫描C++;在模板化父类中调用本地类的源,c++,templates,clang,libtooling,local-class,C++,Templates,Clang,Libtooling,Local Class,要扫描的源代码: template <typename T> class HB { T m; public: void HBfunc1(); }; template <typename T> void HB<T>::HBfunc1() { class HC { public: void HCfunc2() { }; }; HC().HCfunc2(); } void T

要扫描的源代码:

template <typename T>
class HB {
    T m;
public:
    void HBfunc1();
};

template <typename T>
void HB<T>::HBfunc1() {  
    class HC {      
    public:
        void HCfunc2() { };
    };    
    HC().HCfunc2();
}

void TestTemplate() { HB<int>().HBfunc1(); };
被调用者为null,调用者的转储为:

VisitCallExpr:
Now dump call:
CallExpr 0x1c2ef83b3a0 '<dependent type>'
`-CXXDependentScopeMemberExpr 0x1c2ef83b348 '<dependent type>' lvalue .HCfunc2
  `-CXXUnresolvedConstructExpr 0x1c2ef83b320 'class HC' 'class HC'

为什么认为HC类型未知?扫描AST时,是否有任何类型未知,且不会发出任何警告/错误?如何访问这样的调用并提取其被调用方的信息?扫描的代码有问题吗?

在这种情况下,Clang是保守的,因为它将函数调用标记为未解决(又称依赖依赖事物仅出现在模板中。这意味着某些语法结构可能依赖于模板参数

HC
类不是常见的类,您将拥有与
HB
的实例化数量一样多的独立的
HC
类。因此,如果
HC
不使用
T
,那么将其放在
HBfunc1
中几乎没有意义。否则,它确实是依赖的。Clang倾向于安全,避免假设smth在依赖上下文中定义时不依赖

由于这些原因,像这样的AST节点是绝对正常的。这不是解析器错误,一切都按预期进行。根据被叫人的确切信息,简短的回答是-在分析模板时没有办法。但是,clang为每个实例化生成AST。它们具有通常的AST结构,并且可以很容易地访问

我希望这些信息是有用的

HC().HCfunc2();
VisitCallExpr:
Now dump call:
CallExpr 0x1c2ef83b3a0 '<dependent type>'
`-CXXDependentScopeMemberExpr 0x1c2ef83b348 '<dependent type>' lvalue .HCfunc2
  `-CXXUnresolvedConstructExpr 0x1c2ef83b320 'class HC' 'class HC'
// This represents the type of an expression whose type is
// totally unknown, e.g. 'T::foo'.  It is permitted for this to
// appear in situations where the structure of the type is
// theoretically deducible.
BUILTIN_TYPE(Dependent, DependentTy)