Files
2025-10-25 03:02:53 +03:00

243 lines
10 KiB
Markdown
Raw Permalink 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.

[basic.pre]
# 6 Basics [[basic]](./#basic)
## 6.1 Preamble [basic.pre]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L13)
[*Note [1](#note-1)*:
This Clause presents the basic concepts of the C++ language[.](#1.sentence-1)
It explains the difference between an object and a
name and how they relate to the value categories for expressions[.](#1.sentence-2)
It introduces the concepts of a
declaration and a definition and presents C++'s
notion of type, scope, linkage, and
storage duration[.](#1.sentence-3)
The mechanisms for starting and
terminating a program are discussed[.](#1.sentence-4)
Finally, this Clause presents the
fundamental types of the language and lists the ways of constructing
compound types from these[.](#1.sentence-5)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L27)
[*Note [2](#note-2)*:
This Clause does not cover concepts that affect only a single
part of the language[.](#2.sentence-1)
Such concepts are discussed in the relevant
Clauses[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L34)
A [*name*](basic.link#def:name "6.7Program and linkage[basic.link]") is an [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") ([[lex.name]](lex.name "5.11Identifiers")),[*conversion-function-id*](class.conv.fct#nt:conversion-function-id "11.4.8.3Conversion functions[class.conv.fct]") ([[class.conv.fct]](class.conv.fct "11.4.8.3Conversion functions")),[*operator-function-id*](over.oper.general#nt:operator-function-id "12.4.1General[over.oper.general]") ([[over.oper]](over.oper "12.4Overloaded operators")), or[*literal-operator-id*](over.literal#nt:literal-operator-id "12.6User-defined literals[over.literal]") ([[over.literal]](over.literal "12.6User-defined literals"))[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L40)
Two names are [*the same*](#def:name,same "6.1Preamble[basic.pre]") if
- [(4.1)](#4.1)
they are [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]")*s* composed of the same character sequence, or
- [(4.2)](#4.2)
they are [*conversion-function-id*](class.conv.fct#nt:conversion-function-id "11.4.8.3Conversion functions[class.conv.fct]")*s* formed with
equivalent ([[temp.over.link]](temp.over.link "13.7.7.2Function template overloading")) types, or
- [(4.3)](#4.3)
they are [*operator-function-id*](over.oper.general#nt:operator-function-id "12.4.1General[over.oper.general]")*s* formed with
the same operator, or
- [(4.4)](#4.4)
they are [*literal-operator-id*](over.literal#nt:literal-operator-id "12.6User-defined literals[over.literal]")*s* formed with
the same literal suffix identifier[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L52)
Every name is introduced by a [*declaration*](#def:declaration "6.1Preamble[basic.pre]"), which is a
- [(5.1)](#5.1)
[*name-declaration*](dcl.pre#nt:name-declaration "9.1Preamble[dcl.pre]"),[*block-declaration*](dcl.pre#nt:block-declaration "9.1Preamble[dcl.pre]"), or[*member-declaration*](class.mem.general#nt:member-declaration "11.4.1General[class.mem.general]") ([[dcl.pre]](dcl.pre "9.1Preamble"), [[class.mem]](class.mem "11.4Class members")),
- [(5.2)](#5.2)
[*init-declarator*](dcl.decl.general#nt:init-declarator "9.3.1General[dcl.decl.general]") ([[dcl.decl]](dcl.decl "9.3Declarators")),
- [(5.3)](#5.3)
[*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") in a structured binding declaration ([[dcl.struct.bind]](dcl.struct.bind "9.7Structured binding declarations")),
- [(5.4)](#5.4)
[*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") in a [*result-name-introducer*](dcl.contract.res#nt:result-name-introducer "9.4.2Referring to the result object[dcl.contract.res]") in a postcondition assertion ([[dcl.contract.res]](dcl.contract.res "9.4.2Referring to the result object")),
- [(5.5)](#5.5)
[*init-capture*](expr.prim.lambda.capture#nt:init-capture "7.5.6.3Captures[expr.prim.lambda.capture]") ([[expr.prim.lambda.capture]](expr.prim.lambda.capture "7.5.6.3Captures")),
- [(5.6)](#5.6)
[*condition*](stmt.pre#nt:condition "8.1Preamble[stmt.pre]") with a [*declarator*](dcl.decl.general#nt:declarator "9.3.1General[dcl.decl.general]") ([[stmt.pre]](stmt.pre "8.1Preamble")),
- [(5.7)](#5.7)
[*member-declarator*](class.mem.general#nt:member-declarator "11.4.1General[class.mem.general]") ([[class.mem]](class.mem "11.4Class members")),
- [(5.8)](#5.8)
[*using-declarator*](namespace.udecl#nt:using-declarator "9.10The using declaration[namespace.udecl]") ([[namespace.udecl]](namespace.udecl "9.10The using declaration")),
- [(5.9)](#5.9)
[*parameter-declaration*](dcl.fct#nt:parameter-declaration "9.3.4.6Functions[dcl.fct]") ([[dcl.fct]](dcl.fct "9.3.4.6Functions"), [[temp.param]](temp.param "13.2Template parameters")),
- [(5.10)](#5.10)
[*type-parameter*](temp.param#nt:type-parameter "13.2Template parameters[temp.param]") ([[temp.param]](temp.param "13.2Template parameters")),
- [(5.11)](#5.11)
[*type-tt-parameter*](temp.param#nt:type-tt-parameter "13.2Template parameters[temp.param]") ([[temp.param]](temp.param "13.2Template parameters")),
- [(5.12)](#5.12)
[*variable-tt-parameter*](temp.param#nt:variable-tt-parameter "13.2Template parameters[temp.param]") ([[temp.param]](temp.param "13.2Template parameters")),
- [(5.13)](#5.13)
[*concept-tt-parameter*](temp.param#nt:concept-tt-parameter "13.2Template parameters[temp.param]") ([[temp.param]](temp.param "13.2Template parameters")),
- [(5.14)](#5.14)
[*elaborated-type-specifier*](dcl.type.elab#nt:elaborated-type-specifier "9.2.9.5Elaborated type specifiers[dcl.type.elab]") that introduces a name ([[dcl.type.elab]](dcl.type.elab "9.2.9.5Elaborated type specifiers")),
- [(5.15)](#5.15)
[*class-specifier*](class.pre#nt:class-specifier "11.1Preamble[class.pre]") ([[class.pre]](class.pre "11.1Preamble")),
- [(5.16)](#5.16)
[*enum-specifier*](dcl.enum#nt:enum-specifier "9.8.1Enumeration declarations[dcl.enum]") or[*enumerator-definition*](dcl.enum#nt:enumerator-definition "9.8.1Enumeration declarations[dcl.enum]") ([[dcl.enum]](dcl.enum "9.8.1Enumeration declarations")),
- [(5.17)](#5.17)
[*exception-declaration*](except.pre#nt:exception-declaration "14.1Preamble[except.pre]") ([[except.pre]](except.pre "14.1Preamble")), or
- [(5.18)](#5.18)
implicit declaration of an injected-class-name ([[class.pre]](class.pre "11.1Preamble"))[.](#5.sentence-1)
[*Note [3](#note-3)*:
The term declaration is not a synonym for the grammar non-terminal [*declaration*](dcl.pre#nt:declaration "9.1Preamble[dcl.pre]") ([[dcl.pre]](dcl.pre "9.1Preamble"))[.](#5.sentence-2)
— *end note*]
[*Note [4](#note-4)*:
The interpretation of a [*for-range-declaration*](stmt.pre#nt:for-range-declaration "8.1Preamble[stmt.pre]") produces
one or more of the above ([[stmt.ranged]](stmt.ranged "8.6.5The range-based for statement"))[.](#5.sentence-3)
— *end note*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L107)
[*Note [5](#note-5)*:
Some names denote types or templates[.](#6.sentence-1)
In general, whenever a name is encountered
it is necessary to look it up ([[basic.lookup]](basic.lookup "6.5Name lookup"))
to determine whether that name denotes one of these entities
before continuing to parse the program that contains it[.](#6.sentence-2)
— *end note*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L116)
A [*variable*](#def:variable "6.1Preamble[basic.pre]") is introduced by the
declaration of
a reference other than a non-static data member or of
an object[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L122)
An [*entity*](#def:entity "6.1Preamble[basic.pre]") is a
variable,
structured binding,
result binding,
function,
enumerator,
type,
type alias,
non-static data member,
bit-field,
template,
namespace,
namespace alias,
template parameter,
function parameter, or[*init-capture*](expr.prim.lambda.capture#nt:init-capture "7.5.6.3Captures[expr.prim.lambda.capture]")[.](#8.sentence-1)
The [*underlying entity*](#def:entity,underlying "6.1Preamble[basic.pre]") of an entity is that entity
unless otherwise specified[.](#8.sentence-2)
A name [*denotes*](#def:denote "6.1Preamble[basic.pre]") the underlying entity of
the entity declared by each declaration that introduces the name[.](#8.sentence-3)
[*Note [6](#note-6)*:
Type aliases and namespace aliases have underlying entities
that are distinct from themselves[.](#8.sentence-4)
— *end note*]
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L148)
A [*local entity*](#def:entity,local "6.1Preamble[basic.pre]") is a variable with
automatic storage duration ([[basic.stc.auto]](basic.stc.auto "6.8.6.4Automatic storage duration")),
a structured binding ([[dcl.struct.bind]](dcl.struct.bind "9.7Structured binding declarations"))
whose corresponding variable is such an entity,
a result binding ([[dcl.contract.res]](dcl.contract.res "9.4.2Referring to the result object")),
or the *this object ([[expr.prim.this]](expr.prim.this "7.5.3This"))[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L156)
A name used in more than one translation unit can potentially
refer to the same entity in these translation units depending on the[linkage](basic.link "6.7Program and linkage[basic.link]") of the name specified in each
translation unit[.](#10.sentence-1)