<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang_getEnumConstantDeclValue returns 0 for struct template"
   href="https://bugs.llvm.org/show_bug.cgi?id=38518">38518</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang_getEnumConstantDeclValue returns 0 for struct template
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>atila.neves@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>