<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 - Unexpected error "definition with same mangled name as another definition""
   href="https://bugs.llvm.org/show_bug.cgi?id=33924">33924</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unexpected error "definition with same mangled name as another definition"
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>Modules
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>pank.dm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18843" name="attach_18843" title="Files that reproduce the error">attachment 18843</a> <a href="attachment.cgi?id=18843&action=edit" title="Files that reproduce the error">[details]</a></span>
Files that reproduce the error

It triggers on the following piece of code when we try to instantiate templated
function `format` in 2 separate modules:

// -- format.h
class Formatter {
public:
  template <class T>
  void doFormat(T& out) {}
};

template <class T>
void format(T t) {
  Formatter f;
  auto lambda = [] {};
  f.doFormat(lambda);
}

(see full set of files in attachment)
Error message:

In module 'foo1' imported from main.cpp:1:
In module 'format' imported from ./foo1.h:3:
./format.h:6:8: error: definition with same mangled name as another
definition
           void doFormat(T& out) {}
       ^
./format.h:6:8: note: previous definition is here

Seems like this is related to passing lambda from templated function. If I try
to call `doFormat` on regular class or move body of `format` into module `foo`
itself, then the error goes away.

Worth noting there is also assertion triggering when using clang built from
source in debug mode:

llvm/lib/IR/Value.cpp:402: void llvm::Value::doRAUW(llvm::Value*, bool):
Assertion `New->getType() == getType(
) && "replaceAllUses of value with new value of different type!"' failed.

Repro command line:
clang++ --std=c++14 -I .  -fmodules -fcxx-modules
-fmodules-cache-path=./modules_out/_module_cache -c main.cpp -o main.o


A non-modular compilation that uses the same set of files finishes fine.
Let me know if you need any extra information.</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>