Re-declaration of inline function

28 views
Skip to first unread message

razvyb...@gmail.com

unread,
Jan 20, 2018, 3:49:55 AM1/20/18
to ISO C++ Standard - Discussion

Consider the following example (in the same translation unit):


inline void f();
void f() {}


What happens at the redeclaration of f? Is f still considered inline?

I looked in the standard for this situation but I only found the reverse of it in 10.1.6/6 [dcl.inline]:

[...] If the definition of a function or variable appears in a translation unit before its first declaration as inline, the program is ill-formed. [...]

I would like some references in the standard which specify what happens in this situation.

I saw this post on stackoverflow, but it doesn't show an explicit reference in the standard. I'm inclined to believe there is no such reference.


Thank you.

Brian Bi

unread,
Jan 20, 2018, 4:10:17 AM1/20/18
to std-dis...@isocpp.org
[basic.link]/10

> Two names that are the same and that are declared in different scopes shall denote the same variable, function, type, template or namespace if ... when both names denote functions, the parameter-type-lists of the functions ([dcl.fct]) are identical; ...

The presence or absence of the inline specifier is not considered here; thus the subsequent declaration that omits the inline specifier redeclares the same function. But, according to [dcl.inline]/2,

> A function declaration ([dcl.fct], [class.mfct], [class.friend]) with an inline specifier declares an inline function. ...

So the first declaration makes the function inline---the wording implies that it is the function itself that is inline. The function cannot subsequently be made to not be inline without contradicting this sentence.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.

razvyb...@gmail.com

unread,
Jan 20, 2018, 4:16:52 AM1/20/18
to ISO C++ Standard - Discussion
I understand the second part of the answer, but I have problems with the first reference: "Two names that are the same and that are declared in different scopes [...]". 
In my example are the two declarations in different scopes?
[basic.link]/10
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.

Brian Bi

unread,
Jan 20, 2018, 4:37:09 AM1/20/18
to std-dis...@isocpp.org
Oh, I'm sorry. The correct reference for this case is [over.dcl]/1

> Two function declarations of the same name refer to the same function if they are in the same scope and have equivalent parameter declarations ([over.load]) and equivalent trailing requires-clauses, if any ([dcl.decl]). ...

To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.

razvyb...@gmail.com

unread,
Jan 20, 2018, 4:45:26 AM1/20/18
to ISO C++ Standard - Discussion
Ok. I was thinking along the same lines as your explanation. Thank you!
Reply all
Reply to author
Forward
0 new messages