[Clang Modules] error: definition with same mangled name as another definition

I am trying to use Clang Modules, but getting the following error:

error: definition with same mangled name as another definition

Full 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

It seems like the error is happening when we pass lambda as templated argument (see below for minimized example).

Is this error expected? I am not sure how should I fix that as clang points to exactly the same place for previous definition.

Using clang built from latest trunk shows the same error, but also the following failed assertion:

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.

Here is the following self-contained example:
Commandline:
clang++ --std=c++14 -I . -fmodules -fcxx-modules -fmodules-cache-path=./modules_out/_module_cache -c main.cpp -o main.o

Files:
// — main.cpp
#include “foo1.h”
#include “foo2.h”

int main () {
return 0;
}

// – foo1.h
#pragma once

#include “format.h”

void foo1() {
format(0);
}

// – foo2.h
#pragma once

#include “format.h”

void foo2() {
format(0);
}

// – format.h
#pragma once

class Formatter {
public:
template
void doFormat(T& out) {}
};

template
void format(T t) {
Formatter f;
auto lambda = {};
f.doFormat(lambda);
}

// – module.modulemap
module foo1 {
header “foo1.h”
export *
}

module foo2 {
header “foo2.h”
export *
}

module format {
header “format.h”
export *
}

Hi Dmitry,

I am trying to use Clang Modules, but getting the following error:

  error: definition with same mangled name as another definition

Full 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

It seems like the error is happening when we pass lambda as templated
argument (see below for minimized example).

Is this error expected? I am not sure how should I fix that as clang points
to exactly the same place for previous definition.

Looks like it should work, can you file a bug?

Thanks for looking!
Submitted into bugzilla as: https://bugs.llvm.org/show_bug.cgi?id=33924