[llvm-bugs] [Bug 38518] New: clang_getEnumConstantDeclValue returns 0 for struct template
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Aug 10 05:48:03 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38518
Bug ID: 38518
Summary: clang_getEnumConstantDeclValue returns 0 for struct
template
Product: clang
Version: 6.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: libclang
Assignee: unassignedclangbugs at nondot.org
Reporter: atila.neves at gmail.com
CC: klimek at google.com, llvm-bugs at lists.llvm.org
main.cpp
-------------------
#include <iostream>
#include <clang-c/Index.h>
using namespace std;
ostream& operator<<(ostream& stream, const CXString& str) {
stream << clang_getCString(str);
clang_disposeString(str);
return stream;
}
int main(int argc, char* argv[]) {
CXIndex index = clang_createIndex(0, 0);
CXTranslationUnit unit = clang_parseTranslationUnit(
index,
argv[1], nullptr, 0,
nullptr, 0,
CXTranslationUnit_None
);
if (unit == nullptr) {
cerr << "Unable to parse translation unit. Quitting." << endl;
exit(-1);
}
CXCursor cursor = clang_getTranslationUnitCursor(unit);
clang_visitChildren(
cursor,
[](CXCursor cursor, CXCursor, CXClientData)
{
if(clang_getCursorKind(cursor) == CXCursor_EnumConstantDecl) {
cout << "decl ivalue: " << clang_getEnumConstantDeclValue(cursor) <<
endl;
cout << "decl uvalue: " <<
clang_getEnumConstantDeclUnsignedValue(cursor) << endl;
}
return CXChildVisit_Recurse;
//return CXChildVisit_Continue;
},
nullptr);
clang_disposeTranslationUnit(unit);
clang_disposeIndex(index);
}
-------------------
templates.cpp:
-------------------
template<bool, bool, typename>
struct copy_move {
enum { value = 42 };
};
template<>
struct copy_move<false, true, double> {
enum { value = 33 };
};
-------------------
```
$ clang++ main.cpp -lclang && ./a.out templates.cpp
decl ivalue: 0
decl uvalue: 0
decl ivalue: 33
decl uvalue: 33
```
The calls to clang_getEnumConstantDeclValue and
clang_getEnumConstantDeclUnsignedValue both return 0 when they should return
42.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180810/5c41d2c6/attachment.html>
More information about the llvm-bugs
mailing list