THE 1987
THE 1987

Reputation: 45

inline specifier in a friend function declaration

I'm having a question about N4842.

For 9.2.7 The inline specifier, there is

"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.

Upvotes: 4

Views: 124

Answers (1)

SergeyA
SergeyA

Reputation: 62603

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):

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.

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.

Upvotes: 3

Related Questions