[cfe-dev] How to deal with mangled names matching with extern "C" ones?

Renato Golin renato.golin at linaro.org
Tue Jul 7 04:03:07 PDT 2015


On 7 July 2015 at 11:26, Andrey Bokhanko <andreybokhanko at gmail.com> wrote:
> The following test:
> (...)
> crashes clang.

That's a bug. :)

In your case, your C definition is "void ()" while the destructor is
"void (this)", so they are different. Clang is just messing up.


> The problem here is when CodeGen generates code for t's destructor
> call, it tries to find destructor's declaration using its mangled name
> ("_ZN1TD1Ev") as a key... and finds extern "C" function's declaration
> instead. Of course, number of arguments is different, so an assert
> hits.

The standard says:

C++11 7.5 p1: "Two function types with different language linkages are
distinct types even if they are otherwise identical."

However...

C++11 7.5 p5: "If two declarations declare functions with the same
name and parameter-type-list (8.3.5) to be members of the same
namespace or declare objects with the same name to be members of the
same namespace and the declarations give the names different language
linkages, the program is ill-formed; no diagnostic is required if the
declarations appear in different translation units."

My standard-reading skills are a bit rusty, but following the examples
on that chapter, I believe to be an error to have something like:

struct T {
  ~T() {}
};

extern "C" void _ZN1TD1Ev(struct T*);

int main() {
  T t;
  _ZN1TD1Ev(&t);
}

This should be resolved simply by the same mechanism that is already
in place for C++.

Though, g++ seems to accept it...

cheers,
--renato



More information about the cfe-dev mailing list