gpt4 book ai didi

c++ - 友元函数声明中的内联说明符

转载 作者:行者123 更新时间:2023-12-02 17:41:16 25 4
gpt4 key购买 nike

我对 N4842 有疑问。

对于 9.2.7 内联说明符,有

“如果在友元函数声明中使用内联说明符,则该声明应是定义,或者该函数之前应已声明为内联。”

第五段。

但是下面的代码没有发生错误。

struct X{
friend inline void f();
};

void f(){} // no error

为什么没有错误呢?请教我。

最佳答案

似乎是一个编译器错误,我能够在所有三大编译器上重现该错误。这里的标准用语非常明确:

10.1.6/5(最新草案):

If the inline specifier is used in a friend function declaration, that declaration shall be a definition or the function shall have previously been declared inline.

4.1/1:

The set of diagnosable rules consists of all syntactic and semantic rules in this International Standard except for those rules containing an explicit notation that “no diagnostic is required” or which are described as resulting in “undefined behavior”.

...

(2.2) — If a program contains a violation of any diagnosable rule or an occurrence of a construct described in this International Standard as “conditionally-supported” when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message.

由于该规则未标记为“无需诊断”,因此未能提供规则是编译器错误。如果您对此有强烈的感觉,可以提交错误报告。

关于c++ - 友元函数声明中的内联说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59900253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com