Home > Backend Development > C++ > Does Microsoft Visual C Correctly Implement Two-Phase Template Instantiation?

Does Microsoft Visual C Correctly Implement Two-Phase Template Instantiation?

Linda Hamilton
Release: 2024-12-06 02:37:11
Original
561 people have browsed it

Does Microsoft Visual C   Correctly Implement Two-Phase Template Instantiation?

Two-Phase Template Instantiation in Microsoft Visual C

Issue with MSVC 's Template Instantiation

In discussions on Stack Overflow, concerns have emerged regarding Microsoft Visual C (MSVC )'s incorrect implementation of two-phase template instantiation. This process involves an initial syntax check followed by a full function/class body check.

Incomplete Syntax Checking

As it turns out, MSVC performs only a basic syntax check on template entities. It does not fully verify that referenced names have been at least declared, resulting in potential errors being missed.

Incorrect Two-Phase Lookup

Beyond incorrect syntax checking, the two-phase lookup process itself faces issues in MSVC . During the first phase, dependent expressions such as function or member calls are not fully resolved. Instead, MSVC defers resolution to the second phase.

However, the issue with this approach becomes apparent in the second phase. While the standard mandates that only declarations added between the definition and instantiation points can be introduced during the second lookup phase, MSVC does not adhere to this restriction. It extends ordinary unqualified lookup to include declarations that were visible during the first phase, leading to potential binding errors and incorrect execution behavior.

Example Case

One illustrative example that highlights these errors occurs when attempting to resolve the foo(0) expression within a template class S. While a standard-compliant compiler would resolve this call during the first phase and bind it to foo(void*), MSVC defers resolution and attempts to bind it to foo(int), causing an error.

Significance of the Issue

This incorrect implementation affects code functionality and developer experience. It can lead to unexpected errors, which can be difficult to diagnose and resolve. Additionally, it can hinder the portability of code to other compilers and platforms.

Conclusion

The issue of broken two-phase template instantiation in Microsoft Visual C is a significant concern that has been acknowledged by developers. It is important for developers using MSVC to be aware of these problems and take appropriate precautions to avoid unexpected errors.

The above is the detailed content of Does Microsoft Visual C Correctly Implement Two-Phase Template Instantiation?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template