Clang 访问LLVM C+中静态constexpr的初始值设定项+;17
在LLVM-9.x插件中,我想访问与模板专用化Clang 访问LLVM C+中静态constexpr的初始值设定项+;17,clang,clang++,llvm-clang,llvm-c++-api,Clang,Clang++,Llvm Clang,Llvm C++ Api,在LLVM-9.x插件中,我想访问与模板专用化T foo中的变量Y关联的初始值设定项(=42): template<int X> class T { //Clang produces different ASTs on this code in C++14 and C++17 //(in 17, there's no initializer for Y (= 42) in the specialized //class foo below). static const
T foo
中的变量Y
关联的初始值设定项(=42
):
template<int X>
class T {
//Clang produces different ASTs on this code in C++14 and C++17
//(in 17, there's no initializer for Y (= 42) in the specialized
//class foo below).
static constexpr int Y = X;
};
T<42> foo;
而且一切正常(假设decl
是Y
的第二个VarDecl
,我可以通过decl->getInit()访问42
)
然而,使用clang++-std=c++17
,我得到了新的AST:
> clang++ -std=c++17 -Xclang -ast-dump -fsyntax-only file.cpp
|-ClassTemplateDecl 0x56114838ff40 <test_constexpr.cpp:1:1, line:7:1> line:2:7 T
...
| | `-VarDecl 0x561148390258 <line:6:3, col:28> col:24 Y 'const int' static inline constexpr cinit
| | `-DeclRefExpr 0x5611483902c0 <col:28> 'int' NonTypeTemplateParm 0x56114838fe38 'X' 'int'
| `-ClassTemplateSpecializationDecl 0x561148390338 <line:1:1, line:7:1> line:2:7 class T
...
| |-VarDecl 0x561148390688 <line:6:3, col:24> col:24 Y 'const int' static constexpr
>clang++-std=c++17-Xclang-ast dump-fsyntax only file.cpp
|-ClassTemplateDecl 0x56114838ff40行:2:7T
...
||`-VarDecl 0x561148390258列:24 Y“const int”静态内联constexpr cinit
||`-DeclRefExpr 0x5611483902c0'int'非类型模板参数0x56114838fe38'X''int'
|`-ClassTemplateSpecializationDecl 0x561148390338行:2:7类T
...
||-VarDecl 0x561148390688列:24 Y“常量内部”静态常量表达式
其中不再显示Y
(-IntegerLiteral 0x563e38c11140'int'42
)的初始化表达式。在类定义中使用Y
类似int z=Y
会导致重新出现初始值设定项
问题
我是否应该期望在clang++-std=c++17
中看不到上面AST中的初始值设定项表达式
如果是这样,从LLVM-9.x插件中访问T foo
中Y
的初始值设定项的最佳方法是什么
谢谢!如果我遗漏了相关信息,请告诉我——我很乐意更新问题以提供相关信息
> clang++ -std=c++17 -Xclang -ast-dump -fsyntax-only file.cpp
|-ClassTemplateDecl 0x56114838ff40 <test_constexpr.cpp:1:1, line:7:1> line:2:7 T
...
| | `-VarDecl 0x561148390258 <line:6:3, col:28> col:24 Y 'const int' static inline constexpr cinit
| | `-DeclRefExpr 0x5611483902c0 <col:28> 'int' NonTypeTemplateParm 0x56114838fe38 'X' 'int'
| `-ClassTemplateSpecializationDecl 0x561148390338 <line:1:1, line:7:1> line:2:7 class T
...
| |-VarDecl 0x561148390688 <line:6:3, col:24> col:24 Y 'const int' static constexpr