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

Dmitry Panin via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 22 12:31:57 PDT 2017


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 <class T>
  void doFormat(T& out) {}
};


template <class T>
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 *
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170722/d8967886/attachment.html>


More information about the cfe-dev mailing list