<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 - Wrong resolving boost::variant template arguments by formatters API"
   href="https://bugs.llvm.org/show_bug.cgi?id=32300">32300</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong resolving boost::variant template arguments by formatters API
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>andrew.stepanov.i@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>1. Use C++ code:

#include <boost/variant>
#include <vector>
#include <string>

template<typename ParentType>
struct Example
{
    using Variant = boost::variant<int, std::string, std::vector<ParentType>>;
};

int main()
{
    Example<float>::Variant ex(std::string("string"));
    Example<float>::Variant ex2(10);
    return ex.which() == ex2.which();
}


2. Use formatter for boost::variant:

import lldb
import lldb.formatters.Logger

def get_template_arg(valobj, i):
    valobj_type = valobj.GetType().GetUnqualifiedType()
    if valobj_type.IsReferenceType():
        valobj_type = valobj_type.GetDereferencedType()
    if valobj_type.GetNumberOfTemplateArguments() > i:
        data_type = valobj_type.GetTemplateArgumentType(i)
    else:
        data_type = None
    return data_type

class BoostVariantSynthProvider:
    def __init__(self, valobj, dict):
        self.val_obj = valobj
        self.value = None
        self.update()

    def num_children(self):
        return 1

    def has_children(self):
        return True

    def get_child_index(self, name):
        if name == "value":
            return 0

        return -1

    def get_child_at_index(self, index):
        if index == 0:
            return self.value

        return None

    def update(self):
        type_index =
self.val_obj.GetChildMemberWithName("which_").GetValueAsUnsigned()
        element_type = get_template_arg(self.val_obj, type_index)
        self.value =
self.val_obj.GetChildMemberWithName("storage_").GetChildMemberWithName("data_").
\
            GetChildMemberWithName("buf").CreateChildAtOffset("value", 0,
element_type)

Actual:
GetNumberOfTemplateArguments() returns 1 for Example<float>::Variant type and
get_template_arg returns 'None'
Expected:
GetNumberOfTemplateArguments() should return 3 for Example<float>::Variant type
and get_template_arg should returns std::string type</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>