Home > Backend Development > C++ > Is GCC's Extensional Treatment of Non-constexpr Standard Library Functions in Constexpr Contexts Conforming to the C Standard?

Is GCC's Extensional Treatment of Non-constexpr Standard Library Functions in Constexpr Contexts Conforming to the C Standard?

Mary-Kate Olsen
Release: 2024-11-28 21:33:14
Original
884 people have browsed it

Is GCC's Extensional Treatment of Non-constexpr Standard Library Functions in Constexpr Contexts Conforming to the C   Standard?

Is Extensional Treatment of Non-constexpr Library Functions Conforming?

The ability of GCC to treat non-constexpr standard library functions as constexpr in certain situations raises questions regarding conformance.

Contradiction in Standards

In the draft C 11 standard, it appeared that treating built-in functions as constexpr would be explicitly allowed. However, the consensus shifted in C 12, and the proposal changed, resulting in C 14 explicitly prohibiting this behavior.

As-If Rule

In C 11, it was unclear whether the as-if rule permitted this behavior. Some opinions suggested that it might, but this interpretation is not confirmed in the resolution of LWG issue 2013, which deals with this specific topic.

GCC's Implementation

GCC implemented this behavior based on the earlier proposed resolution of LWG 2013, which allowed implicit treatment as constexpr functions. However, the final resolution changed, and this extension is now non-conforming in C 14.

Conformance in Strict Mode

To conform to the C 14 standard, GCC should issue a warning in strict conformance mode (-std=c 11 -pedantic or -std=c 14 -pedantic) when encountering non-constexpr library functions used in constexpr contexts. Alternatively, this behavior should be disabled in these modes.

Intrinsics Exemption

Compiler intrinsics are not covered by the standard, and therefore, they may be treated differently. It is likely that using compiler intrinsics in constexpr contexts remains acceptable.

The above is the detailed content of Is GCC's Extensional Treatment of Non-constexpr Standard Library Functions in Constexpr Contexts Conforming to the C Standard?. 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