Brifing

GCC and Clang Non-Compliance with C++ Standards

GCC and Clang fail to adhere to C++ language linkage standards.

Hacker News: Front Page1 min

1What is Language Linkage?

In C++, function types have a 'language linkage' attribute, which determines their calling conventions. This is typically 'C++' or 'C'. The standard mandates that function types with different language linkages should be treated as distinct types, even if they are otherwise identical.

2GCC and Clang's Approach

GCC and Clang compilers do not store language linkage information with function types. As a result, they treat function types with different linkages as identical, contrary to the standard. This highlights their non-compliance with C++ standards.

3Example Code Issue

In an example code snippet, a function type declared with 'extern C' is compared to a regular function type. The compilers incorrectly consider them the same, whereas the standard requires this comparison to fail. This demonstrates a clear deviation from the specification.

4Overloading Problems

When overloading functions that take function pointer parameters, GCC and Clang may produce incorrect compilation errors. The standard requires parameters with different language linkages to be distinct, but the compilers fail to enforce this rule.

5The Role of Standards

The root of the issue lies in the strict rules set by the standards. Compilers like GCC and Clang are reluctant to change their behavior, as it could break ABI compatibility. Some argue that the standard should update this rule to be 'implementation-defined'.

6Conclusion and Impact

This non-compliance could cause issues in projects using multiple language linkages. While the current behavior doesn't cause major problems in practice, updating the standards could provide a long-term solution. The debate highlights the balance between strict compliance and practical implementation.

Original article: Hacker News: Front Page — GCC ve Clang'ın C++ Standartlarına Uyumsuzluğu