HeadlinesBriefing favicon HeadlinesBriefing.com

GCC Clang Non-Compliant Standard C++ Language Linkage

Hacker News •
×

In C++, function types have a "language linkage" associated with them: this is either "C++", "C", or some other implementation-defined language. The standard explicitly states that two function types with different language linkages are distinct types even if they are otherwise identical.

GCC and Clang however, just don't store language linkage information with the type. So two functions with different language linkages can be identical. A static_assert using std::is_same should fail but doesn't.

This also causes erroneous compilation failures when overloading a function which takes a function pointer parameter. The code should compile, but both compilers think the parameter lists are identical and violate the one definition rule.

The blame lies on the standard, not GCC or Clang. The standard should be updated to make this implementation-defined. Compilers can't change behavior because that would be a breaking ABI change (extern "C" function types in mangled names would be encoded differently). Calling conventions for C and C++ are identical on pretty much every platform.