113 lines
4.1 KiB
Markdown
113 lines
4.1 KiB
Markdown
[dcl.inline]
|
||
|
||
# 9 Declarations [[dcl]](./#dcl)
|
||
|
||
## 9.2 Specifiers [[dcl.spec]](dcl.spec#dcl.inline)
|
||
|
||
### 9.2.8 The inline specifier [dcl.inline]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1092)
|
||
|
||
The inline specifier shall be applied only to the declaration
|
||
of a variable or function[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1096)
|
||
|
||
A function declaration ([[dcl.fct]](dcl.fct "9.3.4.6 Functions"), [[class.mfct]](class.mfct "11.4.2 Member functions"), [[class.friend]](class.friend "11.8.4 Friends"))
|
||
with an inline specifier declares an[*inline function*](#def:function,inline "9.2.8 The inline specifier [dcl.inline]")[.](#2.sentence-1)
|
||
|
||
The inline specifier indicates to
|
||
the implementation that inline substitution of the function body at the
|
||
point of call is to be preferred to the usual function call mechanism[.](#2.sentence-2)
|
||
|
||
An implementation is not required to perform this inline substitution at
|
||
the point of call; however, even if this inline substitution is omitted,
|
||
the other rules for inline functions specified in this subclause shall
|
||
still be respected[.](#2.sentence-3)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
The inline keyword has no effect on the linkage of a function[.](#2.sentence-4)
|
||
|
||
In certain cases, an inline function cannot use names with internal linkage;
|
||
see [[basic.link]](basic.link "6.7 Program and linkage")[.](#2.sentence-5)
|
||
|
||
â *end note*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1114)
|
||
|
||
A variable declaration with an inline specifier declares an[*inline variable*](#def:variable,inline "9.2.8 The inline specifier [dcl.inline]")[.](#3.sentence-1)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1118)
|
||
|
||
The inline specifier shall not appear on a block scope declaration or
|
||
on the declaration of a function parameter[.](#4.sentence-1)
|
||
|
||
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.sentence-2)
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1125)
|
||
|
||
If a definition of a function or variable is reachable
|
||
at the point of its
|
||
first declaration as inline, the program is ill-formed[.](#5.sentence-1)
|
||
|
||
If a function or variable
|
||
with external or module linkage
|
||
is declared inline in one definition domain,
|
||
an inline declaration of it shall be reachable
|
||
from the end of every definition domain in which it is declared;
|
||
no diagnostic is required[.](#5.sentence-2)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
A call to an inline function or a use of an inline variable can be encountered
|
||
before its definition becomes reachable in a translation unit[.](#5.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1139)
|
||
|
||
[*Note [3](#note-3)*:
|
||
|
||
An inline function or variable
|
||
with external or module linkage
|
||
can be defined in multiple translation units ([[basic.def.odr]](basic.def.odr "6.3 One-definition rule")),
|
||
but is one entity with one address[.](#6.sentence-1)
|
||
|
||
A type or static variable
|
||
defined in the body of such a function
|
||
is therefore a single entity[.](#6.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L1150)
|
||
|
||
If an inline function or variable that is attached to a named module
|
||
is declared in a definition domain,
|
||
it shall be defined in that domain[.](#7.sentence-1)
|
||
|
||
[*Note [4](#note-4)*:
|
||
|
||
A [constexpr function](dcl.constexpr#def:specifier,constexpr,function "9.2.6 The constexpr and consteval specifiers [dcl.constexpr]") is implicitly inline[.](#7.sentence-2)
|
||
|
||
In the global module, a function defined within a class definition
|
||
is implicitly inline ([[class.mfct]](class.mfct "11.4.2 Member functions"), [[class.friend]](class.friend "11.8.4 Friends"))[.](#7.sentence-3)
|
||
|
||
â *end note*]
|