简体   繁体   English

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

[英]inline specifier in a friend function declaration

I'm having a question about N4842.我有一个关于 N4842 的问题。

For 9.2.7 The inline specifier, there is对于 9.2.7 内联说明符,有

"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." “如果在友元函数声明中使用了内联说明符,则该声明应为定义,或者该函数之前应已声明为内联。”

in fifth paragraph.在第五段。

But no error has occurred by the following code.但是下面的代码没有发生错误。

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

void f(){} // no error

Why is not there error?为什么没有错误? Please teach me.请教我。

Seems like a compiler bug, which I was able to reproduce on all big 3 compilers.似乎是一个编译器错误,我能够在所有三大编译器上重现。 Standard verbiage here is very explicit:这里的标准措辞非常明确:

10.1.6/5 (latest draft): 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: 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. (2.2)——如果一个程序包含违反任何可诊断规则或出现本国际标准中描述为“有条件支持”的结构,而实现不支持该结构,则符合要求的实现应发出至少一个诊断消息.

Since the rule is not marked as 'no diagnostic is required', failure to provide one is a compiler bug.由于该规则未标记为“不需要诊断”,因此未能提供一个是编译器错误。 If you feeling strongly about it, you can file a bugreport.如果您对此感觉强烈,则可以提交错误报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM