Files
cppdraft_translate/cppdraft/dcl/inline.md
2025-10-25 03:02:53 +03:00

113 lines
4.1 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[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.6Functions"), [[class.mfct]](class.mfct "11.4.2Member functions"), [[class.friend]](class.friend "11.8.4Friends"))
with an inline specifier declares an[*inline function*](#def:function,inline "9.2.8The 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.7Program 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.8The 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.3One-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.6The 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.2Member functions"), [[class.friend]](class.friend "11.8.4Friends"))[.](#7.sentence-3)
— *end note*]