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: unassignedclangb...@nondot.org
          Reporter: atila.ne...@gmail.com
                CC: kli...@google.com, llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to