From Jason Turner

[dcl]

Large diff (308.2 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpsuihoygq/{from.md → to.md} +8800 -0
tmp/tmpsuihoygq/{from.md → to.md} RENAMED
@@ -0,0 +1,8800 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Declarations <a id="dcl">[[dcl]]</a>
2
+
3
+ ## Preamble <a id="dcl.pre">[[dcl.pre]]</a>
4
+
5
+ Declarations generally specify how names are to be interpreted.
6
+ Declarations have the form
7
+
8
+ ``` bnf
9
+ declaration-seq:
10
+ declaration declaration-seqₒₚₜ
11
+ ```
12
+
13
+ ``` bnf
14
+ declaration:
15
+ name-declaration
16
+ special-declaration
17
+ ```
18
+
19
+ ``` bnf
20
+ name-declaration:
21
+ block-declaration
22
+ nodeclspec-function-declaration
23
+ function-definition
24
+ friend-type-declaration
25
+ template-declaration
26
+ deduction-guide
27
+ linkage-specification
28
+ namespace-definition
29
+ empty-declaration
30
+ attribute-declaration
31
+ module-import-declaration
32
+ ```
33
+
34
+ ``` bnf
35
+ special-declaration:
36
+ explicit-instantiation
37
+ explicit-specialization
38
+ export-declaration
39
+ ```
40
+
41
+ ``` bnf
42
+ block-declaration:
43
+ simple-declaration
44
+ asm-declaration
45
+ namespace-alias-definition
46
+ using-declaration
47
+ using-enum-declaration
48
+ using-directive
49
+ static_assert-declaration
50
+ consteval-block-declaration
51
+ alias-declaration
52
+ opaque-enum-declaration
53
+ ```
54
+
55
+ ``` bnf
56
+ nodeclspec-function-declaration:
57
+ attribute-specifier-seqₒₚₜ declarator ';'
58
+ ```
59
+
60
+ ``` bnf
61
+ alias-declaration:
62
+ using identifier attribute-specifier-seqₒₚₜ '=' defining-type-id ';'
63
+ ```
64
+
65
+ ``` bnf
66
+ sb-identifier:
67
+ '...'ₒₚₜ identifier attribute-specifier-seqₒₚₜ
68
+ ```
69
+
70
+ ``` bnf
71
+ sb-identifier-list:
72
+ sb-identifier
73
+ sb-identifier-list ',' sb-identifier
74
+ ```
75
+
76
+ ``` bnf
77
+ structured-binding-declaration:
78
+ attribute-specifier-seqₒₚₜ decl-specifier-seq ref-qualifierₒₚₜ '[' sb-identifier-list ']'
79
+ ```
80
+
81
+ ``` bnf
82
+ simple-declaration:
83
+ decl-specifier-seq init-declarator-listₒₚₜ ';'
84
+ attribute-specifier-seq decl-specifier-seq init-declarator-list ';'
85
+ structured-binding-declaration initializer ';'
86
+ ```
87
+
88
+ ``` bnf
89
+ static_assert-message:
90
+ unevaluated-string
91
+ constant-expression
92
+ ```
93
+
94
+ ``` bnf
95
+ static_assert-declaration:
96
+ static_assert '(' constant-expression ')' ';'
97
+ static_assert '(' constant-expression ',' static_assert-message ')' ';'
98
+ ```
99
+
100
+ ``` bnf
101
+ consteval-block-declaration:
102
+ consteval compound-statement
103
+ ```
104
+
105
+ ``` bnf
106
+ empty-declaration:
107
+ ';'
108
+ ```
109
+
110
+ ``` bnf
111
+ attribute-declaration:
112
+ attribute-specifier-seq ';'
113
+ ```
114
+
115
+ [*Note 1*: *asm-declaration*s are described in  [[dcl.asm]], and
116
+ *linkage-specification*s are described in  [[dcl.link]];
117
+ *function-definition*s are described in  [[dcl.fct.def]] and
118
+ *template-declaration*s and *deduction-guide*s are described in
119
+ [[temp.deduct.guide]]; *namespace-definition*s are described in 
120
+ [[namespace.def]], *using-declaration*s are described in 
121
+ [[namespace.udecl]] and *using-directive*s are described in 
122
+ [[namespace.udir]]. — *end note*]
123
+
124
+ Certain declarations contain one or more scopes [[basic.scope.scope]].
125
+ Unless otherwise stated, utterances in [[dcl]] about components in, of,
126
+ or contained by a declaration or subcomponent thereof refer only to
127
+ those components of the declaration that are *not* nested within scopes
128
+ nested within the declaration.
129
+
130
+ If a *name-declaration* matches the syntactic requirements of
131
+ *friend-type-declaration*, it is a *friend-type-declaration*.
132
+
133
+ A *simple-declaration* or *nodeclspec-function-declaration* of the form
134
+
135
+ ``` bnf
136
+ attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ init-declarator-listₒₚₜ ';'
137
+ ```
138
+
139
+ is divided into three parts. Attributes are described in  [[dcl.attr]].
140
+ *decl-specifier*s, the principal components of a *decl-specifier-seq*,
141
+ are described in  [[dcl.spec]]. *declarator*s, the components of an
142
+ *init-declarator-list*, are described in [[dcl.decl]]. The
143
+ *attribute-specifier-seq* appertains to each of the entities declared by
144
+ the *declarator*s of the *init-declarator-list*.
145
+
146
+ [*Note 2*: In the declaration for an entity, attributes appertaining to
147
+ that entity can appear at the start of the declaration and after the
148
+ *declarator-id* for that declaration. — *end note*]
149
+
150
+ [*Example 1*:
151
+
152
+ ``` cpp
153
+ [[noreturn]] void f [[noreturn]] (); // OK
154
+ ```
155
+
156
+ — *end example*]
157
+
158
+ If a *declarator-id* is a name, the *init-declarator* and (hence) the
159
+ declaration introduce that name.
160
+
161
+ [*Note 3*: Otherwise, the *declarator-id* is a *qualified-id* or names
162
+ a destructor or its *unqualified-id* is a *template-id* and no name is
163
+ introduced. — *end note*]
164
+
165
+ The *defining-type-specifier*s [[dcl.type]] in the *decl-specifier-seq*
166
+ and the recursive *declarator* structure describe a type
167
+ [[dcl.meaning]], which is then associated with the *declarator-id*.
168
+
169
+ In a *simple-declaration*, the optional *init-declarator-list* can be
170
+ omitted only when declaring a class [[class.pre]] or enumeration
171
+ [[dcl.enum]], that is, when the *decl-specifier-seq* contains either a
172
+ *class-specifier*, an *elaborated-type-specifier* with a *class-key*
173
+ [[class.name]], or an *enum-specifier*. In these cases and whenever a
174
+ *class-specifier* or *enum-specifier* is present in the
175
+ *decl-specifier-seq*, the identifiers in these specifiers are also
176
+ declared (as *class-name*s, *enum-name*s, or *enumerator*s, depending on
177
+ the syntax). In such cases, the *decl-specifier-seq* shall (re)introduce
178
+ one or more names into the program.
179
+
180
+ [*Example 2*:
181
+
182
+ ``` cpp
183
+ enum { }; // error
184
+ typedef class { }; // error
185
+ ```
186
+
187
+ — *end example*]
188
+
189
+ A *simple-declaration* or a *condition* with a
190
+ *structured-binding-declaration* is called a *structured binding
191
+ declaration* [[dcl.struct.bind]]. Each *decl-specifier* in the
192
+ *decl-specifier-seq* shall be `constexpr`, `constinit`, `static`,
193
+ `thread_local`, `auto` [[dcl.spec.auto]], or a *cv-qualifier*. The
194
+ declaration shall contain at most one *sb-identifier* whose *identifier*
195
+ is preceded by an ellipsis. If the declaration contains any such
196
+ *sb-identifier*, it shall declare a templated entity [[temp.pre]].
197
+
198
+ [*Example 3*:
199
+
200
+ ``` cpp
201
+ template<class T> concept C = true;
202
+ C auto [x, y] = std::pair{1, 2}; // error: constrained placeholder-type-specifier
203
+ // not permitted for structured bindings
204
+ ```
205
+
206
+ — *end example*]
207
+
208
+ The *initializer* shall be of the form “`=` *assignment-expression*”, of
209
+ the form “`{` *assignment-expression* `}`”, or of the form “`(`
210
+ *assignment-expression* `)`”. If the *structured-binding-declaration*
211
+ appears as a *condition*, the *assignment-expression* shall be of
212
+ non-union class type. Otherwise, the *assignment-expression* shall be of
213
+ array or non-union class type.
214
+
215
+ If the *decl-specifier-seq* contains the `typedef` specifier, the
216
+ declaration is a *typedef declaration* and each *declarator-id* is
217
+ declared to be a *typedef-name* [[dcl.typedef]].
218
+
219
+ [*Note 4*: Such a *declarator-id* is an *identifier*
220
+ [[class.conv.fct]]. — *end note*]
221
+
222
+ Otherwise, if the type associated with a *declarator-id* is a function
223
+ type [[dcl.fct]], the declaration is a *function declaration*.
224
+ Otherwise, if the type associated with a *declarator-id* is an object or
225
+ reference type, the declaration is an *object declaration*. Otherwise,
226
+ the program is ill-formed.
227
+
228
+ [*Example 4*:
229
+
230
+ ``` cpp
231
+ int f(), x; // OK, function declaration for f and object declaration for x
232
+ extern void g(), // OK, function declaration for g
233
+ y; // error: void is not an object type
234
+ ```
235
+
236
+ — *end example*]
237
+
238
+ An object definition causes storage of appropriate size and alignment to
239
+ be reserved and any appropriate initialization [[dcl.init]] to be done.
240
+
241
+ Syntactic components beyond those found in the general form of
242
+ *simple-declaration* are added to a function declaration to make a
243
+ *function-definition*. A token sequence starting with `{` or `=` is
244
+ treated as a *function-body* [[dcl.fct.def.general]] if the type of the
245
+ *declarator-id* [[dcl.meaning.general]] is a function type, and is
246
+ otherwise treated as a *brace-or-equal-initializer*
247
+ [[dcl.init.general]].
248
+
249
+ [*Note 5*: If the declaration acquires a function type through template
250
+ instantiation, the program is ill-formed; see [[temp.spec.general]]. The
251
+ function type of a function definition cannot be specified with a
252
+ *typedef-name* [[dcl.fct]]. — *end note*]
253
+
254
+ A *nodeclspec-function-declaration* shall declare a constructor,
255
+ destructor, or conversion function.
256
+
257
+ [*Note 6*: Because a member function cannot be subject to a
258
+ non-defining declaration outside of a class definition [[class.mfct]], a
259
+ *nodeclspec-function-declaration* can only be used in a
260
+ *template-declaration* [[temp.pre]], *explicit-instantiation*
261
+ [[temp.explicit]], or *explicit-specialization*
262
+ [[temp.expl.spec]]. — *end note*]
263
+
264
+ If a *static_assert-message* matches the syntactic requirements of
265
+ *unevaluated-string*, it is an *unevaluated-string* and the text of the
266
+ *static_assert-message* is the text of the *unevaluated-string*.
267
+ Otherwise, a *static_assert-message* shall be an expression M such that
268
+
269
+ - the expression `M.size()` is implicitly convertible to the type
270
+ `std::size_t`, and
271
+ - the expression `M.data()` is implicitly convertible to the type
272
+ “pointer to `const char`”.
273
+
274
+ In a *static_assert-declaration*, the *constant-expression* E is
275
+ contextually converted to `bool` and the converted expression shall be a
276
+ constant expression [[expr.const]]. If the value of the expression E
277
+ when so converted is `true` or the expression is evaluated in the
278
+ context of a template definition, the declaration has no effect and the
279
+ *static_assert-message* is an unevaluated operand
280
+ [[term.unevaluated.operand]]. Otherwise, the *static_assert-declaration*
281
+ *fails* and
282
+
283
+ - the program is ill-formed, and
284
+ - if the *static_assert-message* is a *constant-expression* M,
285
+ - `M.size()` shall be a converted constant expression of type
286
+ `std::size_t` and let N denote the value of that expression,
287
+ - `M.data()`, implicitly converted to the type “pointer to
288
+ `const char`”, shall be a core constant expression and let D denote
289
+ the converted expression,
290
+ - for each i where 0 ≤ i < N, `D[i]` shall be an integral constant
291
+ expression, and
292
+ - the text of the *static_assert-message* is formed by the sequence of
293
+ N code units, starting at D, of the ordinary literal encoding
294
+ [[lex.charset]].
295
+
296
+ *Recommended practice:* When a *static_assert-declaration* fails, the
297
+ resulting diagnostic message should include the text of the
298
+ *static_assert-message*, if one is supplied.
299
+
300
+ [*Example 5*:
301
+
302
+ ``` cpp
303
+ static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
304
+ static_assert(sizeof(int[2])); // OK, narrowing allowed
305
+
306
+ template <class T>
307
+ void f(T t) {
308
+ if constexpr (sizeof(T) == sizeof(int)) {
309
+ use(t);
310
+ } else {
311
+ static_assert(false, "must be int-sized");
312
+ }
313
+ }
314
+
315
+ void g(char c) {
316
+ f(0); // OK
317
+ f(c); // error on implementations where sizeof(int) > 1: must be int-sized
318
+ }
319
+ ```
320
+
321
+ — *end example*]
322
+
323
+ For a *consteval-block-declaration* D, the expression E corresponding to
324
+ D is:
325
+
326
+ ``` cpp
327
+ []static consteval -> void compound-statement ()
328
+ ```
329
+
330
+ E shall be a constant expression [[expr.const]].
331
+
332
+ [*Note 7*: The evaluation of the expression corresponding to a
333
+ *consteval-block-declaration* [[lex.phases]] can produce injected
334
+ declarations as side effects. — *end note*]
335
+
336
+ [*Example 6*:
337
+
338
+ ``` cpp
339
+ struct S;
340
+ consteval {
341
+ std::meta::define_aggregate(^^S, {}); // OK
342
+
343
+ template<class T>
344
+ struct X { }; // error: local templates are not allowed
345
+
346
+ template<class T>
347
+ concept C = true; // error: local concepts are not allowed
348
+
349
+ return; // OK
350
+ }
351
+ ```
352
+
353
+ — *end example*]
354
+
355
+ An *empty-declaration* has no effect.
356
+
357
+ Except where otherwise specified, the meaning of an
358
+ *attribute-declaration* is *implementation-defined*.
359
+
360
+ ## Specifiers <a id="dcl.spec">[[dcl.spec]]</a>
361
+
362
+ ### General <a id="dcl.spec.general">[[dcl.spec.general]]</a>
363
+
364
+ The specifiers that can be used in a declaration are
365
+
366
+ ``` bnf
367
+ decl-specifier:
368
+ storage-class-specifier
369
+ defining-type-specifier
370
+ function-specifier
371
+ friend
372
+ typedef
373
+ constexpr
374
+ consteval
375
+ constinit
376
+ inline
377
+ ```
378
+
379
+ ``` bnf
380
+ decl-specifier-seq:
381
+ decl-specifier attribute-specifier-seqₒₚₜ
382
+ decl-specifier decl-specifier-seq
383
+ ```
384
+
385
+ The optional *attribute-specifier-seq* in a *decl-specifier-seq*
386
+ appertains to the type determined by the preceding *decl-specifier*s
387
+ [[dcl.meaning]]. The *attribute-specifier-seq* affects the type only for
388
+ the declaration it appears in, not other declarations involving the same
389
+ type.
390
+
391
+ At most one of each of the *decl-specifier*s `friend`, `typedef`, or
392
+ `inline` shall appear in a *decl-specifier-seq*. At most one of the
393
+ `constexpr`, `consteval`, and `constinit` keywords shall appear in a
394
+ *decl-specifier-seq*.
395
+
396
+ If a *type-name* is encountered while parsing a *decl-specifier-seq*, it
397
+ is interpreted as part of the *decl-specifier-seq* if and only if there
398
+ is no previous *defining-type-specifier* other than a *cv-qualifier* in
399
+ the *decl-specifier-seq*. The sequence shall be self-consistent as
400
+ described below.
401
+
402
+ [*Example 1*:
403
+
404
+ ``` cpp
405
+ typedef char* Pc;
406
+ static Pc; // error: name missing
407
+ ```
408
+
409
+ Here, the declaration `static` `Pc` is ill-formed because no name was
410
+ specified for the static variable of type `Pc`. To get a variable called
411
+ `Pc`, a *type-specifier* (other than `const` or `volatile`) has to be
412
+ present to indicate that the *typedef-name* `Pc` is the name being
413
+ (re)declared, rather than being part of the *decl-specifier* sequence.
414
+ For another example,
415
+
416
+ ``` cpp
417
+ void f(const Pc); // void f(char* const) (not const char*)
418
+ void g(const int Pc); // void g(const int)
419
+ ```
420
+
421
+ — *end example*]
422
+
423
+ [*Note 1*:
424
+
425
+ Since `signed`, `unsigned`, `long`, and `short` by default imply `int`,
426
+ a *type-name* appearing after one of those specifiers is treated as the
427
+ name being (re)declared.
428
+
429
+ [*Example 2*:
430
+
431
+ ``` cpp
432
+ void h(unsigned Pc); // void h(unsigned int)
433
+ void k(unsigned int Pc); // void k(unsigned int)
434
+ ```
435
+
436
+ — *end example*]
437
+
438
+ — *end note*]
439
+
440
+ ### Storage class specifiers <a id="dcl.stc">[[dcl.stc]]</a>
441
+
442
+ The storage class specifiers are
443
+
444
+ ``` bnf
445
+ storage-class-specifier:
446
+ static
447
+ thread_local
448
+ extern
449
+ mutable
450
+ ```
451
+
452
+ At most one *storage-class-specifier* shall appear in a given
453
+ *decl-specifier-seq*, except that `thread_local` may appear with
454
+ `static` or `extern`. If `thread_local` appears in any declaration of a
455
+ variable it shall be present in all declarations of that entity. If a
456
+ *storage-class-specifier* appears in a *decl-specifier-seq*, there can
457
+ be no `typedef` specifier in the same *decl-specifier-seq* and the
458
+ *init-declarator-list* or *member-declarator-list* of the declaration
459
+ shall not be empty (except for an anonymous union declared in a
460
+ namespace scope [[class.union.anon]]). The *storage-class-specifier*
461
+ applies to the name declared by each *init-declarator* in the list and
462
+ not to any names declared by other specifiers.
463
+
464
+ [*Note 1*: See [[temp.expl.spec]] and [[temp.explicit]] for
465
+ restrictions in explicit specializations and explicit instantiations,
466
+ respectively. — *end note*]
467
+
468
+ [*Note 2*: A variable declared without a *storage-class-specifier* at
469
+ block scope or declared as a function parameter has automatic storage
470
+ duration by default [[basic.stc.auto]]. — *end note*]
471
+
472
+ The `thread_local` specifier indicates that the named entity has thread
473
+ storage duration [[basic.stc.thread]]. It shall be applied only to the
474
+ declaration of a variable of namespace or block scope, to a structured
475
+ binding declaration [[dcl.struct.bind]], or to the declaration of a
476
+ static data member. When `thread_local` is applied to a variable of
477
+ block scope the *storage-class-specifier* `static` is implied if no
478
+ other *storage-class-specifier* appears in the *decl-specifier-seq*.
479
+
480
+ The `static` specifier shall be applied only to the declaration of a
481
+ variable or function, to a structured binding declaration
482
+ [[dcl.struct.bind]], or to the declaration of an anonymous union
483
+ [[class.union.anon]]. There can be no `static` function declarations
484
+ within a block, nor any `static` function parameters. A `static`
485
+ specifier used in the declaration of a variable declares the variable to
486
+ have static storage duration [[basic.stc.static]], unless accompanied by
487
+ the `thread_local` specifier, which declares the variable to have thread
488
+ storage duration [[basic.stc.thread]]. A `static` specifier can be used
489
+ in declarations of class members;  [[class.static]] describes its
490
+ effect. For the linkage of a name declared with a `static` specifier,
491
+ see  [[basic.link]].
492
+
493
+ The `extern` specifier shall be applied only to the declaration of a
494
+ variable or function. The `extern` specifier shall not be used in the
495
+ declaration of a class member or function parameter. For the linkage of
496
+ a name declared with an `extern` specifier, see  [[basic.link]].
497
+
498
+ [*Note 3*: The `extern` keyword can also be used in
499
+ *explicit-instantiation*s and *linkage-specification*s, but it is not a
500
+ *storage-class-specifier* in such contexts. — *end note*]
501
+
502
+ All declarations for a given entity shall give its name the same
503
+ linkage.
504
+
505
+ [*Note 4*: The linkage given by some declarations is affected by
506
+ previous declarations. Overloads are distinct entities. — *end note*]
507
+
508
+ [*Example 1*:
509
+
510
+ ``` cpp
511
+ static char* f(); // f() has internal linkage
512
+ char* f() // f() still has internal linkage
513
+ { ... }
514
+
515
+ char* g(); // g() has external linkage
516
+ static char* g() // error: inconsistent linkage
517
+ { ... }
518
+
519
+ void h();
520
+ inline void h(); // external linkage
521
+
522
+ inline void l();
523
+ void l(); // external linkage
524
+
525
+ inline void m();
526
+ extern void m(); // external linkage
527
+
528
+ static void n();
529
+ inline void n(); // internal linkage
530
+
531
+ static int a; // a has internal linkage
532
+ int a; // error: two definitions
533
+
534
+ static int b; // b has internal linkage
535
+ extern int b; // b still has internal linkage
536
+
537
+ int c; // c has external linkage
538
+ static int c; // error: inconsistent linkage
539
+
540
+ extern int d; // d has external linkage
541
+ static int d; // error: inconsistent linkage
542
+ ```
543
+
544
+ — *end example*]
545
+
546
+ The name of a declared but undefined class can be used in an `extern`
547
+ declaration. Such a declaration can only be used in ways that do not
548
+ require a complete class type.
549
+
550
+ [*Example 2*:
551
+
552
+ ``` cpp
553
+ struct S;
554
+ extern S a;
555
+ extern S f();
556
+ extern void g(S);
557
+
558
+ void h() {
559
+ g(a); // error: S is incomplete
560
+ f(); // error: S is incomplete
561
+ }
562
+ ```
563
+
564
+ — *end example*]
565
+
566
+ The `mutable` specifier shall appear only in the declaration of a
567
+ non-static data member [[class.mem]] whose type is neither
568
+ const-qualified nor a reference type.
569
+
570
+ [*Example 3*:
571
+
572
+ ``` cpp
573
+ class X {
574
+ mutable const int* p; // OK
575
+ mutable int* const q; // error
576
+ };
577
+ ```
578
+
579
+ — *end example*]
580
+
581
+ [*Note 5*: The `mutable` specifier on a class data member nullifies a
582
+ `const` specifier applied to the containing class object and permits
583
+ modification of the mutable class member even though the rest of the
584
+ object is const
585
+ [[basic.type.qualifier]], [[dcl.type.cv]]. — *end note*]
586
+
587
+ ### Function specifiers <a id="dcl.fct.spec">[[dcl.fct.spec]]</a>
588
+
589
+ A *function-specifier* can be used only in a function declaration. At
590
+ most one *explicit-specifier* and at most one `virtual` keyword shall
591
+ appear in a *decl-specifier-seq*.
592
+
593
+ ``` bnf
594
+ function-specifier:
595
+ virtual
596
+ explicit-specifier
597
+ ```
598
+
599
+ ``` bnf
600
+ explicit-specifier:
601
+ explicit '(' constant-expression ')'
602
+ explicit
603
+ ```
604
+
605
+ The `virtual` specifier shall be used only in the initial declaration of
606
+ a non-static member function; see  [[class.virtual]].
607
+
608
+ An *explicit-specifier* shall be used only in the declaration of a
609
+ constructor or conversion function within its class definition; see 
610
+ [[class.conv.ctor]] and  [[class.conv.fct]].
611
+
612
+ In an *explicit-specifier*, the *constant-expression*, if supplied,
613
+ shall be a contextually converted constant expression of type `bool`
614
+ [[expr.const]]. The *explicit-specifier* `explicit` without a
615
+ *constant-expression* is equivalent to the *explicit-specifier*
616
+ `explicit(true)`. If the constant expression evaluates to `true`, the
617
+ function is explicit. Otherwise, the function is not explicit. A `(`
618
+ token that follows `explicit` is parsed as part of the
619
+ *explicit-specifier*.
620
+
621
+ [*Example 1*:
622
+
623
+ ``` cpp
624
+ struct S {
625
+ explicit(sizeof(char[2])) S(char); // error: narrowing conversion of value 2 to type bool
626
+ explicit(sizeof(char)) S(bool); // OK, conversion of value 1 to type bool is non-narrowing
627
+ };
628
+ ```
629
+
630
+ — *end example*]
631
+
632
+ ### The `typedef` specifier <a id="dcl.typedef">[[dcl.typedef]]</a>
633
+
634
+ Declarations containing the *decl-specifier* `typedef` declare *type
635
+ aliases*. The `typedef` specifier shall not be combined in a
636
+ *decl-specifier-seq* with any other kind of specifier except a
637
+ *defining-type-specifier*, and it shall not be used in the
638
+ *decl-specifier-seq* of a *parameter-declaration* [[dcl.fct]] nor in the
639
+ *decl-specifier-seq* of a *function-definition* [[dcl.fct.def]]. If a
640
+ `typedef` specifier appears in a declaration without a *declarator*, the
641
+ program is ill-formed.
642
+
643
+ ``` bnf
644
+ typedef-name:
645
+ identifier
646
+ simple-template-id
647
+ ```
648
+
649
+ A name declared with the `typedef` specifier becomes a *typedef-name*.
650
+ The underlying entity of the type alias is the type associated with the
651
+ *identifier* [[dcl.decl]] or *simple-template-id* [[temp.pre]]. A
652
+ *typedef-name* does not introduce a new type the way a class declaration
653
+ [[class.name]] or enum declaration [[dcl.enum]] does.
654
+
655
+ [*Example 1*:
656
+
657
+ After
658
+
659
+ ``` cpp
660
+ typedef int MILES, *KLICKSP;
661
+ ```
662
+
663
+ the constructions
664
+
665
+ ``` cpp
666
+ MILES distance;
667
+ extern KLICKSP metricp;
668
+ ```
669
+
670
+ are all correct declarations; the type of `distance` is `int` and that
671
+ of `metricp` is “pointer to `int`”.
672
+
673
+ — *end example*]
674
+
675
+ A type alias can also be declared by an *alias-declaration*. The
676
+ *identifier* following the `using` keyword is not looked up; it becomes
677
+ the *typedef-name* of a type alias and the optional
678
+ *attribute-specifier-seq* following the *identifier* appertains to that
679
+ type alias. Such a type alias has the same semantics as if it were
680
+ introduced by the `typedef` specifier.
681
+
682
+ [*Example 2*:
683
+
684
+ ``` cpp
685
+ using handler_t = void (*)(int);
686
+ extern handler_t ignore;
687
+ extern void (*ignore)(int); // redeclare ignore
688
+ template<class T> struct P { };
689
+ using cell = P<cell*>; // error: cell not found[basic.scope.pdecl]
690
+ ```
691
+
692
+ — *end example*]
693
+
694
+ The *defining-type-specifier-seq* of the *defining-type-id* shall not
695
+ define a class or enumeration if the *alias-declaration* is the
696
+ *declaration* of a *template-declaration*.
697
+
698
+ A *simple-template-id* is only a *typedef-name* if its *template-name*
699
+ names an alias template or a type template template parameter.
700
+
701
+ [*Note 1*: A *simple-template-id* that names a class template
702
+ specialization is a *class-name* [[class.name]]. If a *typedef-name* is
703
+ used to identify the subject of an *elaborated-type-specifier*
704
+ [[dcl.type.elab]], a class definition [[class]], a constructor
705
+ declaration [[class.ctor]], or a destructor declaration [[class.dtor]],
706
+ the program is ill-formed. — *end note*]
707
+
708
+ [*Example 3*:
709
+
710
+ ``` cpp
711
+ struct S {
712
+ S();
713
+ ~S();
714
+ };
715
+
716
+ typedef struct S T;
717
+
718
+ S a = T(); // OK
719
+ struct T * p; // error
720
+ ```
721
+
722
+ — *end example*]
723
+
724
+ An unnamed class or enumeration C defined in a typedef declaration has
725
+ the first *typedef-name* declared by the declaration to be of type C as
726
+ its *typedef name for linkage purposes* [[basic.link]].
727
+
728
+ [*Note 2*: A typedef declaration involving a *lambda-expression* does
729
+ not itself define the associated closure type, and so the closure type
730
+ is not given a typedef name for linkage purposes. — *end note*]
731
+
732
+ [*Example 4*:
733
+
734
+ ``` cpp
735
+ typedef struct { } *ps, S; // S is the typedef name for linkage purposes
736
+ typedef decltype([]{}) C; // the closure type has no typedef name for linkage purposes
737
+ ```
738
+
739
+ — *end example*]
740
+
741
+ An unnamed class with a typedef name for linkage purposes shall not
742
+
743
+ - declare any members other than non-static data members, member
744
+ enumerations, or member classes,
745
+ - have any base classes or default member initializers, or
746
+ - contain a *lambda-expression*,
747
+
748
+ and all member classes shall also satisfy these requirements
749
+ (recursively).
750
+
751
+ [*Example 5*:
752
+
753
+ ``` cpp
754
+ typedef struct {
755
+ int f() {}
756
+ } X; // error: struct with typedef name for linkage has member functions
757
+ ```
758
+
759
+ — *end example*]
760
+
761
+ ### The `friend` specifier <a id="dcl.friend">[[dcl.friend]]</a>
762
+
763
+ The `friend` specifier is used to specify access to class members; see 
764
+ [[class.friend]].
765
+
766
+ ### The `constexpr` and `consteval` specifiers <a id="dcl.constexpr">[[dcl.constexpr]]</a>
767
+
768
+ The `constexpr` specifier shall be applied only to the definition of a
769
+ variable or variable template, a structured binding declaration, or the
770
+ declaration of a function or function template. The `consteval`
771
+ specifier shall be applied only to the declaration of a function or
772
+ function template. A function or static data member declared with the
773
+ `constexpr` or `consteval` specifier on its first declaration is
774
+ implicitly an inline function or variable [[dcl.inline]]. If any
775
+ declaration of a function or function template has a `constexpr` or
776
+ `consteval` specifier, then all its declarations shall contain the same
777
+ specifier.
778
+
779
+ [*Note 1*: An explicit specialization can differ from the template
780
+ declaration with respect to the `constexpr` or `consteval`
781
+ specifier. — *end note*]
782
+
783
+ [*Note 2*: Function parameters cannot be declared
784
+ `constexpr`. — *end note*]
785
+
786
+ [*Example 1*:
787
+
788
+ ``` cpp
789
+ constexpr void square(int &x); // OK, declaration
790
+ constexpr int bufsz = 1024; // OK, definition
791
+ constexpr struct pixel { // error: pixel is a type
792
+ int x;
793
+ int y;
794
+ constexpr pixel(int); // OK, declaration
795
+ };
796
+ constexpr pixel::pixel(int a)
797
+ : x(a), y(x) // OK, definition
798
+ { square(x); }
799
+ constexpr pixel small(2); // error: square not defined, so small(2)
800
+ // not constant[expr.const] so constexpr not satisfied
801
+
802
+ constexpr void square(int &x) { // OK, definition
803
+ x *= x;
804
+ }
805
+ constexpr pixel large(4); // OK, square defined
806
+ int next(constexpr int x) { // error: not for parameters
807
+ return x + 1;
808
+ }
809
+ extern constexpr int memsz; // error: not a definition
810
+ ```
811
+
812
+ — *end example*]
813
+
814
+ A `constexpr` or `consteval` specifier used in the declaration of a
815
+ function declares that function to be a *constexpr function*.
816
+
817
+ [*Note 3*: A function declared with the `consteval` specifier is an
818
+ immediate function [[expr.const]]. — *end note*]
819
+
820
+ A destructor, an allocation function, or a deallocation function shall
821
+ not be declared with the `consteval` specifier.
822
+
823
+ A function is *constexpr-suitable* if it is not a coroutine
824
+ [[dcl.fct.def.coroutine]].
825
+
826
+ Except for instantiated constexpr functions, non-templated constexpr
827
+ functions shall be constexpr-suitable.
828
+
829
+ [*Example 2*:
830
+
831
+ ``` cpp
832
+ constexpr int square(int x)
833
+ { return x * x; } // OK
834
+ constexpr long long_max()
835
+ { return 2147483647; } // OK
836
+ constexpr int abs(int x) {
837
+ if (x < 0)
838
+ x = -x;
839
+ return x; // OK
840
+ }
841
+ constexpr int constant_non_42(int n) { // OK
842
+ if (n == 42) {
843
+ static int value = n;
844
+ return value;
845
+ }
846
+ return n;
847
+ }
848
+ constexpr int uninit() {
849
+ struct { int a; } s;
850
+ return s.a; // error: uninitialized read of s.a
851
+ }
852
+ constexpr int prev(int x)
853
+ { return --x; } // OK
854
+ constexpr int g(int x, int n) { // OK
855
+ int r = 1;
856
+ while (--n > 0) r *= x;
857
+ return r;
858
+ }
859
+ ```
860
+
861
+ — *end example*]
862
+
863
+ An invocation of a constexpr function in a given context produces the
864
+ same result as an invocation of an equivalent non-constexpr function in
865
+ the same context in all respects except that
866
+
867
+ - an invocation of a constexpr function can appear in a constant
868
+ expression [[expr.const]] and
869
+ - copy elision is not performed in a constant expression
870
+ [[class.copy.elision]].
871
+
872
+ [*Note 4*: Declaring a function constexpr can change whether an
873
+ expression is a constant expression. This can indirectly cause calls to
874
+ `std::is_constant_evaluated` within an invocation of the function to
875
+ produce a different value. — *end note*]
876
+
877
+ [*Note 5*: It is possible to write a constexpr function for which no
878
+ invocation satisfies the requirements of a core constant
879
+ expression. — *end note*]
880
+
881
+ The `constexpr` and `consteval` specifiers have no effect on the type of
882
+ a constexpr function.
883
+
884
+ [*Example 3*:
885
+
886
+ ``` cpp
887
+ constexpr int bar(int x, int y) // OK
888
+ { return x + y + x*y; }
889
+ // ...
890
+ int bar(int x, int y) // error: redefinition of bar
891
+ { return x * 2 + 3 * y; }
892
+ ```
893
+
894
+ — *end example*]
895
+
896
+ A `constexpr` specifier used in an object declaration declares the
897
+ object as const. Such an object shall have literal type and shall be
898
+ initialized. A `constexpr` variable shall be constant-initializable
899
+ [[expr.const]]. A `constexpr` variable that is an object, as well as any
900
+ temporary to which a `constexpr` reference is bound, shall have constant
901
+ destruction.
902
+
903
+ [*Example 4*:
904
+
905
+ ``` cpp
906
+ struct pixel {
907
+ int x, y;
908
+ };
909
+ constexpr pixel ur = { 1294, 1024 }; // OK
910
+ constexpr pixel origin; // error: initializer missing
911
+
912
+ namespace N {
913
+ void f() {
914
+ int x;
915
+ constexpr int& ar = x; // OK
916
+ static constexpr int& sr = x; // error: x is not constexpr-representable
917
+ // at the point indicated below
918
+ }
919
+ // immediate scope here is that of N
920
+ }
921
+ ```
922
+
923
+ — *end example*]
924
+
925
+ ### The `constinit` specifier <a id="dcl.constinit">[[dcl.constinit]]</a>
926
+
927
+ The `constinit` specifier shall be applied only to a declaration of a
928
+ variable with static or thread storage duration or to a structured
929
+ binding declaration [[dcl.struct.bind]].
930
+
931
+ [*Note 1*: A structured binding declaration introduces a uniquely named
932
+ variable, to which the `constinit` specifier applies. — *end note*]
933
+
934
+ If the specifier is applied to any declaration of a variable, it shall
935
+ be applied to the initializing declaration. No diagnostic is required if
936
+ no `constinit` declaration is reachable at the point of the initializing
937
+ declaration.
938
+
939
+ If a variable declared with the `constinit` specifier has dynamic
940
+ initialization [[basic.start.dynamic]], the program is ill-formed, even
941
+ if the implementation would perform that initialization as a static
942
+ initialization [[basic.start.static]].
943
+
944
+ [*Note 2*: The `constinit` specifier ensures that the variable is
945
+ initialized during static initialization. — *end note*]
946
+
947
+ [*Example 1*:
948
+
949
+ ``` cpp
950
+ const char * g() { return "dynamic initialization"; }
951
+ constexpr const char * f(bool p) { return p ? "constant initializer" : g(); }
952
+ constinit const char * c = f(true); // OK
953
+ constinit const char * d = f(false); // error
954
+ ```
955
+
956
+ — *end example*]
957
+
958
+ ### The `inline` specifier <a id="dcl.inline">[[dcl.inline]]</a>
959
+
960
+ The `inline` specifier shall be applied only to the declaration of a
961
+ function or variable. The `inline` specifier shall not appear on a block
962
+ scope declaration or on the declaration of a function parameter. If the
963
+ `inline` specifier is used in a friend function declaration, that
964
+ declaration shall be a definition or the function shall have previously
965
+ been declared inline.
966
+
967
+ A function declaration [[dcl.fct]], [[class.mfct]], [[class.friend]]
968
+ with an `inline` specifier declares an *inline function*. A variable
969
+ declaration with an `inline` specifier declares an *inline variable*.
970
+
971
+ [*Note 1*: An inline function or variable with external or module
972
+ linkage can be defined in multiple translation units [[basic.def.odr]],
973
+ but is one entity with one address. A type or `static` variable defined
974
+ in the body of such a function is therefore a single
975
+ entity. — *end note*]
976
+
977
+ [*Note 2*: The `inline` keyword has no effect on the linkage of a
978
+ function. In certain cases, an inline function cannot use names with
979
+ internal linkage; see  [[basic.link]]. — *end note*]
980
+
981
+ The inline specifier indicates to the implementation that inline
982
+ substitution of the function body at the point of call is to be
983
+ preferred to the usual function call mechanism. An implementation is not
984
+ required to perform this inline substitution at the point of call;
985
+ however, even if this inline substitution is omitted, the other rules
986
+ for inline functions specified in this subclause shall still be
987
+ respected.
988
+
989
+ If a definition of a function or variable is reachable at the point of
990
+ its first declaration as inline, the program is ill-formed. If a
991
+ function or variable with external or module linkage is declared inline
992
+ in one definition domain, an inline declaration of it shall be reachable
993
+ from the end of every definition domain in which it is declared; no
994
+ diagnostic is required.
995
+
996
+ [*Note 3*: A call to an inline function or a use of an inline variable
997
+ can be encountered before its definition becomes reachable in a
998
+ translation unit. — *end note*]
999
+
1000
+ If an inline function or variable that is attached to a named module is
1001
+ declared in a definition domain, it shall be defined in that domain.
1002
+
1003
+ [*Note 4*: A constexpr function [[dcl.constexpr]] is implicitly inline.
1004
+ In the global module, a function defined within a class definition is
1005
+ implicitly inline [[class.mfct]], [[class.friend]]. — *end note*]
1006
+
1007
+ ### Type specifiers <a id="dcl.type">[[dcl.type]]</a>
1008
+
1009
+ #### General <a id="dcl.type.general">[[dcl.type.general]]</a>
1010
+
1011
+ The type-specifiers are
1012
+
1013
+ ``` bnf
1014
+ type-specifier:
1015
+ simple-type-specifier
1016
+ elaborated-type-specifier
1017
+ typename-specifier
1018
+ cv-qualifier
1019
+ ```
1020
+
1021
+ ``` bnf
1022
+ type-specifier-seq:
1023
+ type-specifier attribute-specifier-seqₒₚₜ
1024
+ type-specifier type-specifier-seq
1025
+ ```
1026
+
1027
+ ``` bnf
1028
+ defining-type-specifier:
1029
+ type-specifier
1030
+ class-specifier
1031
+ enum-specifier
1032
+ ```
1033
+
1034
+ ``` bnf
1035
+ defining-type-specifier-seq:
1036
+ defining-type-specifier attribute-specifier-seqₒₚₜ
1037
+ defining-type-specifier defining-type-specifier-seq
1038
+ ```
1039
+
1040
+ The optional *attribute-specifier-seq* in a *type-specifier-seq* or a
1041
+ *defining-type-specifier-seq* appertains to the type denoted by the
1042
+ preceding *type-specifier*s or *defining-type-specifier*s
1043
+ [[dcl.meaning]]. The *attribute-specifier-seq* affects the type only for
1044
+ the declaration it appears in, not other declarations involving the same
1045
+ type.
1046
+
1047
+ As a general rule, at most one *defining-type-specifier* is allowed in
1048
+ the complete *decl-specifier-seq* of a *declaration* or in a
1049
+ *defining-type-specifier-seq*, and at most one *type-specifier* is
1050
+ allowed in a *type-specifier-seq*. The only exceptions to this rule are
1051
+ the following:
1052
+
1053
+ - `const` can be combined with any type specifier except itself.
1054
+ - `volatile` can be combined with any type specifier except itself.
1055
+ - `signed` or `unsigned` can be combined with `char`, `long`, `short`,
1056
+ or `int`.
1057
+ - `short` or `long` can be combined with `int`.
1058
+ - `long` can be combined with `double`.
1059
+ - `long` can be combined with `long`.
1060
+
1061
+ Except in a declaration of a constructor, destructor, or conversion
1062
+ function, at least one *defining-type-specifier* that is not a
1063
+ *cv-qualifier* shall appear in a complete *type-specifier-seq* or a
1064
+ complete *decl-specifier-seq*.[^1]
1065
+
1066
+ [*Note 1*: *enum-specifier*s, *class-specifier*s, and
1067
+ *typename-specifier*s are discussed in [[dcl.enum]], [[class]], and
1068
+ [[temp.res]], respectively. The remaining *type-specifier*s are
1069
+ discussed in the rest of [[dcl.type]]. — *end note*]
1070
+
1071
+ #### The *cv-qualifier*s <a id="dcl.type.cv">[[dcl.type.cv]]</a>
1072
+
1073
+ There are two *cv-qualifier*s, `const` and `volatile`. Each
1074
+ *cv-qualifier* shall appear at most once in a *cv-qualifier-seq*. If a
1075
+ *cv-qualifier* appears in a *decl-specifier-seq*, the
1076
+ *init-declarator-list* or *member-declarator-list* of the declaration
1077
+ shall not be empty.
1078
+
1079
+ [*Note 1*: [[basic.type.qualifier]] and [[dcl.fct]] describe how
1080
+ cv-qualifiers affect object and function types. — *end note*]
1081
+
1082
+ Redundant cv-qualifications are ignored.
1083
+
1084
+ [*Note 2*: For example, these could be introduced by
1085
+ typedefs. — *end note*]
1086
+
1087
+ [*Note 3*: Declaring a variable `const` can affect its linkage
1088
+ [[dcl.stc]] and its usability in constant expressions [[expr.const]]. As
1089
+ described in  [[dcl.init]], the definition of an object or subobject of
1090
+ const-qualified type must specify an initializer or be subject to
1091
+ default-initialization. — *end note*]
1092
+
1093
+ A pointer or reference to a cv-qualified type need not actually point or
1094
+ refer to a cv-qualified object, but it is treated as if it does; a
1095
+ const-qualified access path cannot be used to modify an object even if
1096
+ the object referenced is a non-const object and can be modified through
1097
+ some other access path.
1098
+
1099
+ [*Note 4*: Cv-qualifiers are supported by the type system so that they
1100
+ cannot be subverted without casting [[expr.const.cast]]. — *end note*]
1101
+
1102
+ Any attempt to modify
1103
+ [[expr.assign]], [[expr.post.incr]], [[expr.pre.incr]] a const object
1104
+ [[basic.type.qualifier]] during its lifetime [[basic.life]] results in
1105
+ undefined behavior.
1106
+
1107
+ [*Example 1*:
1108
+
1109
+ ``` cpp
1110
+ const int ci = 3; // cv-qualified (initialized as required)
1111
+ ci = 4; // error: attempt to modify const
1112
+
1113
+ int i = 2; // not cv-qualified
1114
+ const int* cip; // pointer to const int
1115
+ cip = &i; // OK, cv-qualified access path to unqualified
1116
+ *cip = 4; // error: attempt to modify through ptr to const
1117
+
1118
+ int* ip;
1119
+ ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
1120
+ *ip = 4; // defined: *ip points to i, a non-const object
1121
+
1122
+ const int* ciq = new const int (3); // initialized as required
1123
+ int* iq = const_cast<int*>(ciq); // cast required
1124
+ *iq = 4; // undefined behavior: modifies a const object
1125
+ ```
1126
+
1127
+ For another example,
1128
+
1129
+ ``` cpp
1130
+ struct X {
1131
+ mutable int i;
1132
+ int j;
1133
+ };
1134
+ struct Y {
1135
+ X x;
1136
+ Y();
1137
+ };
1138
+
1139
+ const Y y;
1140
+ y.x.i++; // well-formed: mutable member can be modified
1141
+ y.x.j++; // error: const-qualified member modified
1142
+ Y* p = const_cast<Y*>(&y); // cast away const-ness of y
1143
+ p->x.i = 99; // well-formed: mutable member can be modified
1144
+ p->x.j = 99; // undefined behavior: modifies a const subobject
1145
+ ```
1146
+
1147
+ — *end example*]
1148
+
1149
+ The semantics of an access through a volatile glvalue are
1150
+ *implementation-defined*. If an attempt is made to access an object
1151
+ defined with a volatile-qualified type through the use of a non-volatile
1152
+ glvalue, the behavior is undefined.
1153
+
1154
+ [*Note 5*: `volatile` is a hint to the implementation to avoid
1155
+ aggressive optimization involving the object because it is possible for
1156
+ the value of the object to change by means undetectable by an
1157
+ implementation. Furthermore, for some implementations, `volatile` can
1158
+ indicate that special hardware instructions are needed to access the
1159
+ object. See  [[intro.execution]] for detailed semantics. In general, the
1160
+ semantics of `volatile` are intended to be the same in C++ as they are
1161
+ in C. — *end note*]
1162
+
1163
+ #### Simple type specifiers <a id="dcl.type.simple">[[dcl.type.simple]]</a>
1164
+
1165
+ The simple type specifiers are
1166
+
1167
+ ``` bnf
1168
+ simple-type-specifier:
1169
+ nested-name-specifierₒₚₜ type-name
1170
+ nested-name-specifier template simple-template-id
1171
+ computed-type-specifier
1172
+ placeholder-type-specifier
1173
+ nested-name-specifierₒₚₜ template-name
1174
+ char
1175
+ char8_t
1176
+ char16_t
1177
+ char32_t
1178
+ wchar_t
1179
+ bool
1180
+ short
1181
+ int
1182
+ long
1183
+ signed
1184
+ unsigned
1185
+ float
1186
+ double
1187
+ void
1188
+ ```
1189
+
1190
+ ``` bnf
1191
+ type-name:
1192
+ class-name
1193
+ enum-name
1194
+ typedef-name
1195
+ ```
1196
+
1197
+ ``` bnf
1198
+ computed-type-specifier:
1199
+ decltype-specifier
1200
+ pack-index-specifier
1201
+ splice-type-specifier
1202
+ ```
1203
+
1204
+ The component names of a *simple-type-specifier* are those of its
1205
+ *nested-name-specifier*, *type-name*, *simple-template-id*,
1206
+ *template-name*, and/or *type-constraint* (if it is a
1207
+ *placeholder-type-specifier*). The component name of a *type-name* is
1208
+ the first name in it.
1209
+
1210
+ A *placeholder-type-specifier* is a placeholder for a type to be deduced
1211
+ [[dcl.spec.auto]]. A *type-specifier* is a placeholder for a deduced
1212
+ class type [[dcl.type.class.deduct]] if either
1213
+
1214
+ - it is of the form `typename`ₒₚₜ *nested-name-specifier*ₒₚₜ
1215
+ *template-name* or
1216
+ - it is of the form `typename`ₒₚₜ *splice-specifier* and the
1217
+ *splice-specifier* designates a class template or alias template.
1218
+
1219
+ The *nested-name-specifier* or *splice-specifier*, if any, shall be
1220
+ non-dependent and the *template-name* or *splice-specifier* shall
1221
+ designate a deducible template. A *deducible template* is either a class
1222
+ template or is an alias template whose *defining-type-id* is of the form
1223
+
1224
+ ``` bnf
1225
+ typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
1226
+ ```
1227
+
1228
+ where the *nested-name-specifier* (if any) is non-dependent and the
1229
+ *template-name* of the *simple-template-id* names a deducible template.
1230
+
1231
+ [*Note 1*: An injected-class-name is never interpreted as a
1232
+ *template-name* in contexts where class template argument deduction
1233
+ would be performed [[temp.local]]. — *end note*]
1234
+
1235
+ The other *simple-type-specifier*s specify either a previously-declared
1236
+ type, a type determined from an expression, or one of the fundamental
1237
+ types [[basic.fundamental]]. [[dcl.type.simple]] summarizes the valid
1238
+ combinations of *simple-type-specifier*s and the types they specify.
1239
+
1240
+ **Table: *simple-type-specifier*{s} and the types they specify** <a id="dcl.type.simple">[dcl.type.simple]</a>
1241
+
1242
+ | Specifier(s) | Type |
1243
+ | ---------------------------- | ------------------------------------------------- |
1244
+ | *type-name* | the type named |
1245
+ | *simple-template-id* | the type as defined in~ [[temp.names]] |
1246
+ | *decltype-specifier* | the type as defined in~ [[dcl.type.decltype]] |
1247
+ | *pack-index-specifier* | the type as defined in~ [[dcl.type.pack.index]] |
1248
+ | *placeholder-type-specifier* | the type as defined in~ [[dcl.spec.auto]] |
1249
+ | *template-name* | the type as defined in~ [[dcl.type.class.deduct]] |
1250
+ | *splice-type-specifier* | the type as defined in~ [[dcl.type.splice]] |
1251
+ | `char` | ```char`'' |
1252
+ | `unsigned char` | ```unsigned char`'' |
1253
+ | `signed char` | ```signed char`'' |
1254
+ | `char8_t` | ```char8_t`'' |
1255
+ | `char16_t` | ```char16_t`'' |
1256
+ | `char32_t` | ```char32_t`'' |
1257
+ | `bool` | ```bool`'' |
1258
+ | `unsigned` | ```unsigned int`'' |
1259
+ | `unsigned int` | ```unsigned int`'' |
1260
+ | `signed` | ```int`'' |
1261
+ | `signed int` | ```int`'' |
1262
+ | `int` | ```int`'' |
1263
+ | `unsigned short int` | ```unsigned short int`'' |
1264
+ | `unsigned short` | ```unsigned short int`'' |
1265
+ | `unsigned long int` | ```unsigned long int`'' |
1266
+ | `unsigned long` | ```unsigned long int`'' |
1267
+ | `unsigned long long int` | ```unsigned long long int`'' |
1268
+ | `unsigned long long` | ```unsigned long long int`'' |
1269
+ | `signed long int` | ```long int`'' |
1270
+ | `signed long` | ```long int`'' |
1271
+ | `signed long long int` | ```long long int`'' |
1272
+ | `signed long long` | ```long long int`'' |
1273
+ | `long long int` | ```long long int`'' |
1274
+ | `long long` | ```long long int`'' |
1275
+ | `long int` | ```long int`'' |
1276
+ | `long` | ```long int`'' |
1277
+ | `signed short int` | ```short int`'' |
1278
+ | `signed short` | ```short int`'' |
1279
+ | `short int` | ```short int`'' |
1280
+ | `short` | ```short int`'' |
1281
+ | `wchar_t` | ```wchar_t`'' |
1282
+ | `float` | ```float`'' |
1283
+ | `double` | ```double`'' |
1284
+ | `long double` | ```long double`'' |
1285
+ | `void` | ```void`'' |
1286
+
1287
+
1288
+ When multiple *simple-type-specifier*s are allowed, they can be freely
1289
+ intermixed with other *decl-specifier*s in any order.
1290
+
1291
+ [*Note 2*: It is *implementation-defined* whether objects of `char`
1292
+ type are represented as signed or unsigned quantities. The `signed`
1293
+ specifier forces `char` objects to be signed; it is redundant in other
1294
+ contexts. — *end note*]
1295
+
1296
+ #### Pack indexing specifier <a id="dcl.type.pack.index">[[dcl.type.pack.index]]</a>
1297
+
1298
+ ``` bnf
1299
+ pack-index-specifier:
1300
+ typedef-name '...' '[' constant-expression ']'
1301
+ ```
1302
+
1303
+ The *typedef-name* P in a *pack-index-specifier* shall denote a pack.
1304
+
1305
+ The *constant-expression* shall be a converted constant expression
1306
+ [[expr.const]] of type `std::size_t` whose value V, termed the index, is
1307
+ such that 0 ≤ V < `sizeof...($P$)`.
1308
+
1309
+ A *pack-index-specifier* is a pack expansion [[temp.variadic]].
1310
+
1311
+ [*Note 1*: The *pack-index-specifier* denotes the type of the Vᵗʰ
1312
+ element of the pack. — *end note*]
1313
+
1314
+ #### Elaborated type specifiers <a id="dcl.type.elab">[[dcl.type.elab]]</a>
1315
+
1316
+ ``` bnf
1317
+ elaborated-type-specifier:
1318
+ class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
1319
+ class-key simple-template-id
1320
+ class-key nested-name-specifier templateₒₚₜ simple-template-id
1321
+ enum nested-name-specifierₒₚₜ identifier
1322
+ ```
1323
+
1324
+ The component names of an *elaborated-type-specifier* are its
1325
+ *identifier* (if any) and those of its *nested-name-specifier* and
1326
+ *simple-template-id* (if any).
1327
+
1328
+ If an *elaborated-type-specifier* is the sole constituent of a
1329
+ declaration, the declaration is ill-formed unless it is an explicit
1330
+ specialization [[temp.expl.spec]], a partial specialization
1331
+ [[temp.spec.partial]], an explicit instantiation [[temp.explicit]], or
1332
+ it has one of the following forms:
1333
+
1334
+ ``` bnf
1335
+ class-key attribute-specifier-seqₒₚₜ identifier ';'
1336
+ class-key attribute-specifier-seqₒₚₜ simple-template-id ';'
1337
+ ```
1338
+
1339
+ In the first case, the *elaborated-type-specifier* declares the
1340
+ *identifier* as a *class-name*. The second case shall appear only in an
1341
+ *explicit-specialization* [[temp.expl.spec]] or in a
1342
+ *template-declaration* (where it declares a partial specialization). The
1343
+ *attribute-specifier-seq*, if any, appertains to the class or template
1344
+ being declared.
1345
+
1346
+ Otherwise, an *elaborated-type-specifier* E shall not have an
1347
+ *attribute-specifier-seq*. If E contains an *identifier* but no
1348
+ *nested-name-specifier* and (unqualified) lookup for the *identifier*
1349
+ finds nothing, E shall not be introduced by the `enum` keyword and
1350
+ declares the *identifier* as a *class-name*. The target scope of E is
1351
+ the nearest enclosing namespace or block scope.
1352
+
1353
+ A *friend-type-specifier* that is an *elaborated-type-specifier* shall
1354
+ have one of the following forms:
1355
+
1356
+ ``` bnf
1357
+ class-key nested-name-specifierₒₚₜ identifier
1358
+ class-key simple-template-id
1359
+ class-key nested-name-specifier templateₒₚₜ simple-template-id
1360
+ ```
1361
+
1362
+ Any unqualified lookup for the *identifier* (in the first case) does not
1363
+ consider scopes that contain the nearest enclosing namespace or block
1364
+ scope; no name is bound.
1365
+
1366
+ [*Note 1*: A *using-directive* in the target scope is ignored if it
1367
+ refers to a namespace not contained by that scope. — *end note*]
1368
+
1369
+ [*Note 2*: [[basic.lookup.elab]] describes how name lookup proceeds in
1370
+ an *elaborated-type-specifier*. An *elaborated-type-specifier* can be
1371
+ used to refer to a previously declared *class-name* or *enum-name* even
1372
+ if the name has been hidden by a non-type declaration. — *end note*]
1373
+
1374
+ If the *identifier* or *simple-template-id* in an
1375
+ *elaborated-type-specifier* resolves to a *class-name* or *enum-name*,
1376
+ the *elaborated-type-specifier* introduces it into the declaration the
1377
+ same way a *simple-type-specifier* introduces its *type-name*
1378
+ [[dcl.type.simple]]. If the *identifier* or *simple-template-id*
1379
+ resolves to a *typedef-name* [[dcl.typedef]], [[temp.names]], the
1380
+ *elaborated-type-specifier* is ill-formed.
1381
+
1382
+ [*Note 3*:
1383
+
1384
+ This implies that, within a class template with a template
1385
+ *type-parameter* `T`, the declaration
1386
+
1387
+ ``` cpp
1388
+ friend class T;
1389
+ ```
1390
+
1391
+ is ill-formed. However, the similar declaration `friend T;` is
1392
+ well-formed [[class.friend]].
1393
+
1394
+ — *end note*]
1395
+
1396
+ The *class-key* or `enum` keyword present in an
1397
+ *elaborated-type-specifier* shall agree in kind with the declaration to
1398
+ which the name in the *elaborated-type-specifier* refers. This rule also
1399
+ applies to the form of *elaborated-type-specifier* that declares a
1400
+ *class-name* or friend class since it can be construed as referring to
1401
+ the definition of the class. Thus, in any *elaborated-type-specifier*,
1402
+ the `enum` keyword shall be used to refer to an enumeration
1403
+ [[dcl.enum]], the `union` *class-key* shall be used to refer to a union
1404
+ [[class.union]], and either the `class` or `struct` *class-key* shall be
1405
+ used to refer to a non-union class [[class.pre]].
1406
+
1407
+ [*Example 1*:
1408
+
1409
+ ``` cpp
1410
+ enum class E { a, b };
1411
+ enum E x = E::a; // OK
1412
+ struct S { } s;
1413
+ class S* p = &s; // OK
1414
+ ```
1415
+
1416
+ — *end example*]
1417
+
1418
+ #### Decltype specifiers <a id="dcl.type.decltype">[[dcl.type.decltype]]</a>
1419
+
1420
+ ``` bnf
1421
+ decltype-specifier:
1422
+ decltype '(' expression ')'
1423
+ ```
1424
+
1425
+ For an expression E, the type denoted by `decltype(E)` is defined as
1426
+ follows:
1427
+
1428
+ - if E is an unparenthesized *id-expression* naming a structured binding
1429
+ [[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
1430
+ the specification of the structured binding declaration;
1431
+ - otherwise, if E is an unparenthesized *id-expression* naming a
1432
+ constant template parameter [[temp.param]], `decltype(E)` is the type
1433
+ of the template parameter after performing any necessary type
1434
+ deduction [[dcl.spec.auto]], [[dcl.type.class.deduct]];
1435
+ - otherwise, if E is an unparenthesized *id-expression* or an
1436
+ unparenthesized class member access [[expr.ref]], `decltype(E)` is the
1437
+ type of the entity named by E. If there is no such entity, the program
1438
+ is ill-formed;
1439
+ - otherwise, if E is an unparenthesized *splice-expression*,
1440
+ `decltype(E)` is the type of the entity, object, or value designated
1441
+ by the *splice-specifier* of E;
1442
+ - otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
1443
+ type of E;
1444
+ - otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
1445
+ type of E;
1446
+ - otherwise, `decltype(E)` is the type of E.
1447
+
1448
+ The operand of the `decltype` specifier is an unevaluated operand
1449
+ [[term.unevaluated.operand]].
1450
+
1451
+ [*Example 1*:
1452
+
1453
+ ``` cpp
1454
+ const int&& foo();
1455
+ int i;
1456
+ struct A { double x; };
1457
+ const A* a = new A();
1458
+ decltype(foo()) x1 = 17; // type is const int&&
1459
+ decltype(i) x2; // type is int
1460
+ decltype(a->x) x3; // type is double
1461
+ decltype((a->x)) x4 = x3; // type is const double&
1462
+ decltype([:^^x1:]) x5 = 18; // type is const int&&
1463
+ decltype(([:^^x1:])) x6 = 19; // type is const int&
1464
+
1465
+ void f() {
1466
+ [](auto ...pack) {
1467
+ decltype(pack...[0]) x7; // type is int
1468
+ decltype((pack...[0])) x8; // type is int&
1469
+ }(0);
1470
+ }
1471
+ ```
1472
+
1473
+ — *end example*]
1474
+
1475
+ [*Note 1*: The rules for determining types involving `decltype(auto)`
1476
+ are specified in  [[dcl.spec.auto]]. — *end note*]
1477
+
1478
+ If the operand of a *decltype-specifier* is a prvalue and is not a
1479
+ (possibly parenthesized) immediate invocation [[expr.const]], the
1480
+ temporary materialization conversion is not applied [[conv.rval]] and no
1481
+ result object is provided for the prvalue. The type of the prvalue may
1482
+ be incomplete or an abstract class type.
1483
+
1484
+ [*Note 2*: As a result, storage is not allocated for the prvalue and it
1485
+ is not destroyed. Thus, a class type is not instantiated as a result of
1486
+ being the type of a function call in this context. In this context, the
1487
+ common purpose of writing the expression is merely to refer to its type.
1488
+ In that sense, a *decltype-specifier* is analogous to a use of a
1489
+ *typedef-name*, so the usual reasons for requiring a complete type do
1490
+ not apply. In particular, it is not necessary to allocate storage for a
1491
+ temporary object or to enforce the semantic constraints associated with
1492
+ invoking the type’s destructor. — *end note*]
1493
+
1494
+ [*Note 3*: Unlike the preceding rule, parentheses have no special
1495
+ meaning in this context. — *end note*]
1496
+
1497
+ [*Example 2*:
1498
+
1499
+ ``` cpp
1500
+ template<class T> struct A { ~A() = delete; };
1501
+ template<class T> auto h()
1502
+ -> A<T>;
1503
+ template<class T> auto i(T) // identity
1504
+ -> T;
1505
+ template<class T> auto f(T) // #1
1506
+ -> decltype(i(h<T>())); // forces completion of A<T> and implicitly uses A<T>::~A()
1507
+ // for the temporary introduced by the use of h().
1508
+ // (A temporary is not introduced as a result of the use of i().)
1509
+ template<class T> auto f(T) // #2
1510
+ -> void;
1511
+ auto g() -> void {
1512
+ f(42); // OK, calls #2. (#1 is not a viable candidate: type deduction
1513
+ // fails[temp.deduct] because A<int>::~A() is implicitly used in its
1514
+ // decltype-specifier)
1515
+ }
1516
+ template<class T> auto q(T)
1517
+ -> decltype((h<T>())); // does not force completion of A<T>; A<T>::~A() is not implicitly
1518
+ // used within the context of this decltype-specifier
1519
+ void r() {
1520
+ q(42); // error: deduction against q succeeds, so overload resolution selects
1521
+ // the specialization ``q(T) -> decltype((h<T>()))'' with T=int;
1522
+ // the return type is A<int>, so a temporary is introduced and its
1523
+ // destructor is used, so the program is ill-formed
1524
+ }
1525
+ ```
1526
+
1527
+ — *end example*]
1528
+
1529
+ #### Placeholder type specifiers <a id="dcl.spec.auto">[[dcl.spec.auto]]</a>
1530
+
1531
+ ##### General <a id="dcl.spec.auto.general">[[dcl.spec.auto.general]]</a>
1532
+
1533
+ ``` bnf
1534
+ placeholder-type-specifier:
1535
+ type-constraintₒₚₜ auto
1536
+ type-constraintₒₚₜ decltype '(' auto ')'
1537
+ ```
1538
+
1539
+ A *placeholder-type-specifier* designates a placeholder type that will
1540
+ be replaced later, typically by deduction from an initializer.
1541
+
1542
+ The type of a *parameter-declaration* of a
1543
+
1544
+ - function declaration [[dcl.fct]],
1545
+ - *lambda-expression* [[expr.prim.lambda]], or
1546
+ - *template-parameter* [[temp.param]]
1547
+
1548
+ can be declared using a *placeholder-type-specifier* of the form
1549
+ *type-constraint*ₒₚₜ `auto`. The placeholder type shall appear as one
1550
+ of the *decl-specifier*s in the *decl-specifier-seq* or as one of the
1551
+ *type-specifier*s in a *trailing-return-type* that specifies the type
1552
+ that replaces such a *decl-specifier* (see below); the placeholder type
1553
+ is a *generic parameter type placeholder* of the function declaration,
1554
+ *lambda-expression*, or *template-parameter*, respectively.
1555
+
1556
+ [*Note 1*: Having a generic parameter type placeholder signifies that
1557
+ the function is an abbreviated function template [[dcl.fct]] or the
1558
+ lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
1559
+
1560
+ A placeholder type can appear in the *decl-specifier-seq* for a function
1561
+ declarator that includes a *trailing-return-type* [[dcl.fct]].
1562
+
1563
+ A placeholder type can appear in the *decl-specifier-seq* or
1564
+ *type-specifier-seq* in the declared return type of a function
1565
+ declarator that declares a function; the return type of the function is
1566
+ deduced from non-discarded `return` statements, if any, in the body of
1567
+ the function [[stmt.if]].
1568
+
1569
+ The type of a variable declared using a placeholder type is deduced from
1570
+ its initializer. This use is allowed in an initializing declaration
1571
+ [[dcl.init]] of a variable. The placeholder type shall appear as one of
1572
+ the *decl-specifier*s in the *decl-specifier-seq* or as one of the
1573
+ *type-specifier*s in a *trailing-return-type* that specifies the type
1574
+ that replaces such a *decl-specifier*; the *decl-specifier-seq* shall be
1575
+ followed by one or more *declarator*s, each of which shall be followed
1576
+ by a non-empty *initializer*.
1577
+
1578
+ [*Example 1*:
1579
+
1580
+ ``` cpp
1581
+ auto x = 5; // OK, x has type int
1582
+ const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
1583
+ static auto y = 0.0; // OK, y has type double
1584
+ auto int r; // error: auto is not a storage-class-specifier
1585
+ auto f() -> int; // OK, f returns int
1586
+ auto g() { return 0.0; } // OK, g returns double
1587
+ auto (*fp)() -> auto = f; // OK
1588
+ auto h(); // OK, h's return type will be deduced when it is defined
1589
+ ```
1590
+
1591
+ — *end example*]
1592
+
1593
+ The `auto` *type-specifier* can also be used to introduce a structured
1594
+ binding declaration [[dcl.struct.bind]].
1595
+
1596
+ A placeholder type can also be used in the *type-specifier-seq* of the
1597
+ *new-type-id* or in the *type-id* of a *new-expression* [[expr.new]]. In
1598
+ such a *type-id*, the placeholder type shall appear as one of the
1599
+ *type-specifier*s in the *type-specifier-seq* or as one of the
1600
+ *type-specifier*s in a *trailing-return-type* that specifies the type
1601
+ that replaces such a *type-specifier*.
1602
+
1603
+ The `auto` *type-specifier* can also be used as the
1604
+ *simple-type-specifier* in an explicit type conversion (functional
1605
+ notation) [[expr.type.conv]].
1606
+
1607
+ A program that uses a placeholder type in a context not explicitly
1608
+ allowed in [[dcl.spec.auto]] is ill-formed.
1609
+
1610
+ If the *init-declarator-list* contains more than one *init-declarator*,
1611
+ they shall all form declarations of variables. The type of each declared
1612
+ variable is determined by placeholder type deduction
1613
+ [[dcl.type.auto.deduct]], and if the type that replaces the placeholder
1614
+ type is not the same in each deduction, the program is ill-formed.
1615
+
1616
+ [*Example 2*:
1617
+
1618
+ ``` cpp
1619
+ auto x = 5, *y = &x; // OK, auto is int
1620
+ auto a = 5, b = { 1, 2 }; // error: different types for auto
1621
+ ```
1622
+
1623
+ — *end example*]
1624
+
1625
+ If a function with a declared return type that contains a placeholder
1626
+ type has multiple non-discarded `return` statements, the return type is
1627
+ deduced for each such `return` statement. If the type deduced is not the
1628
+ same in each deduction, the program is ill-formed.
1629
+
1630
+ If a function with a declared return type that uses a placeholder type
1631
+ has no non-discarded `return` statements, the return type is deduced as
1632
+ though from a `return` statement with no operand at the closing brace of
1633
+ the function body.
1634
+
1635
+ [*Example 3*:
1636
+
1637
+ ``` cpp
1638
+ auto f() { } // OK, return type is void
1639
+ auto* g() { } // error: cannot deduce auto* from void()
1640
+ ```
1641
+
1642
+ — *end example*]
1643
+
1644
+ An exported function with a declared return type that uses a placeholder
1645
+ type shall be defined in the translation unit containing its exported
1646
+ declaration, outside the *private-module-fragment* (if any).
1647
+
1648
+ [*Note 2*: The deduced return type cannot have a name with internal
1649
+ linkage [[basic.link]]. — *end note*]
1650
+
1651
+ If a variable or function with an undeduced placeholder type is named by
1652
+ an expression [[basic.def.odr]], the program is ill-formed. Once a
1653
+ non-discarded `return` statement has been seen in a function, however,
1654
+ the return type deduced from that statement can be used in the rest of
1655
+ the function, including in other `return` statements.
1656
+
1657
+ [*Example 4*:
1658
+
1659
+ ``` cpp
1660
+ auto n = n; // error: n's initializer refers to n
1661
+ auto f();
1662
+ void g() { &f; } // error: f's return type is unknown
1663
+ auto sum(int i) {
1664
+ if (i == 1)
1665
+ return i; // sum's return type is int
1666
+ else
1667
+ return sum(i-1)+i; // OK, sum's return type has been deduced
1668
+ }
1669
+ ```
1670
+
1671
+ — *end example*]
1672
+
1673
+ A result binding never has an undeduced placeholder type
1674
+ [[dcl.contract.res]].
1675
+
1676
+ [*Example 5*:
1677
+
1678
+ ``` cpp
1679
+ auto f()
1680
+ post(r : r == 7) // OK
1681
+ {
1682
+ return 7;
1683
+ }
1684
+ ```
1685
+
1686
+ — *end example*]
1687
+
1688
+ Return type deduction for a templated function with a placeholder in its
1689
+ declared type occurs when the definition is instantiated even if the
1690
+ function body contains a `return` statement with a non-type-dependent
1691
+ operand.
1692
+
1693
+ [*Note 3*: Therefore, any use of a specialization of the function
1694
+ template will cause an implicit instantiation. Any errors that arise
1695
+ from this instantiation are not in the immediate context of the function
1696
+ type and can result in the program being ill-formed
1697
+ [[temp.deduct]]. — *end note*]
1698
+
1699
+ [*Example 6*:
1700
+
1701
+ ``` cpp
1702
+ template <class T> auto f(T t) { return t; } // return type deduced at instantiation time
1703
+ typedef decltype(f(1)) fint_t; // instantiates f<int> to deduce return type
1704
+ template<class T> auto f(T* t) { return *t; }
1705
+ void g() { int (*p)(int*) = &f; } // instantiates both fs to determine return types,
1706
+ // chooses second
1707
+ ```
1708
+
1709
+ — *end example*]
1710
+
1711
+ If a function or function template F has a declared return type that
1712
+ uses a placeholder type, redeclarations or specializations of F shall
1713
+ use that placeholder type, not a deduced type; otherwise, they shall not
1714
+ use a placeholder type.
1715
+
1716
+ [*Example 7*:
1717
+
1718
+ ``` cpp
1719
+ auto f();
1720
+ auto f() { return 42; } // return type is int
1721
+ auto f(); // OK
1722
+ int f(); // error: auto and int don't match
1723
+ decltype(auto) f(); // error: auto and decltype(auto) don't match
1724
+
1725
+ template <typename T> auto g(T t) { return t; } // #1
1726
+ template auto g(int); // OK, return type is int
1727
+ template char g(char); // error: no matching template
1728
+ template<> auto g(double); // OK, forward declaration with unknown return type
1729
+
1730
+ template <class T> T g(T t) { return t; } // OK, not functionally equivalent to #1
1731
+ template char g(char); // OK, now there is a matching template
1732
+ template auto g(float); // still matches #1
1733
+
1734
+ void h() { return g(42); } // error: ambiguous
1735
+
1736
+ template <typename T> struct A {
1737
+ friend T frf(T);
1738
+ };
1739
+ auto frf(int i) { return i; } // not a friend of A<int>
1740
+ extern int v;
1741
+ auto v = 17; // OK, redeclares v
1742
+ struct S {
1743
+ static int i;
1744
+ };
1745
+ auto S::i = 23; // OK
1746
+ ```
1747
+
1748
+ — *end example*]
1749
+
1750
+ A function declared with a return type that uses a placeholder type
1751
+ shall not be `virtual` [[class.virtual]].
1752
+
1753
+ A function declared with a return type that uses a placeholder type
1754
+ shall not be a coroutine [[dcl.fct.def.coroutine]].
1755
+
1756
+ An explicit instantiation declaration [[temp.explicit]] does not cause
1757
+ the instantiation of an entity declared using a placeholder type, but it
1758
+ also does not prevent that entity from being instantiated as needed to
1759
+ determine its type.
1760
+
1761
+ [*Example 8*:
1762
+
1763
+ ``` cpp
1764
+ template <typename T> auto f(T t) { return t; }
1765
+ extern template auto f(int); // does not instantiate f<int>
1766
+ int (*p)(int) = f; // instantiates f<int> to determine its return type, but an explicit
1767
+ // instantiation definition is still required somewhere in the program
1768
+ ```
1769
+
1770
+ — *end example*]
1771
+
1772
+ ##### Placeholder type deduction <a id="dcl.type.auto.deduct">[[dcl.type.auto.deduct]]</a>
1773
+
1774
+ *Placeholder type deduction* is the process by which a type containing a
1775
+ placeholder type is replaced by a deduced type.
1776
+
1777
+ A type `T` containing a placeholder type, and a corresponding
1778
+ *initializer-clause* E, are determined as follows:
1779
+
1780
+ - For a non-discarded `return` statement that occurs in a function
1781
+ declared with a return type that contains a placeholder type, `T` is
1782
+ the declared return type.
1783
+ - If the `return` statement has no operand, then E is `void()`.
1784
+ - If the operand is a *braced-init-list* [[dcl.init.list]], the
1785
+ program is ill-formed.
1786
+ - If the operand is an *expression* X that is not an
1787
+ *assignment-expression*, E is `(X)`. \[*Note 4*: A comma expression
1788
+ [[expr.comma]] is not an *assignment-expression*. — *end note*]
1789
+ - Otherwise, E is the operand of the `return` statement.
1790
+
1791
+ If E has type `void`, `T` shall be either *type-constraint*ₒₚₜ
1792
+ `decltype(auto)` or cv *type-constraint*ₒₚₜ `auto`.
1793
+ - For a variable declared with a type that contains a placeholder type,
1794
+ `T` is the declared type of the variable.
1795
+ - If the initializer of the variable is a *brace-or-equal-initializer*
1796
+ of the form `= initializer-clause`, E is the *initializer-clause*.
1797
+ - If the initializer is a *braced-init-list*, it shall consist of a
1798
+ single brace-enclosed *assignment-expression* and E is the
1799
+ *assignment-expression*.
1800
+ - If the initializer is a parenthesized *expression-list*, the
1801
+ *expression-list* shall be a single *assignment-expression* and E is
1802
+ the *assignment-expression*.
1803
+ - For an explicit type conversion [[expr.type.conv]], `T` is the
1804
+ specified type, which shall be `auto`.
1805
+ - If the initializer is a *braced-init-list*, it shall consist of a
1806
+ single brace-enclosed *assignment-expression* and E is the
1807
+ *assignment-expression*.
1808
+ - If the initializer is a parenthesized *expression-list*, the
1809
+ *expression-list* shall be a single *assignment-expression* and E is
1810
+ the *assignment-expression*.
1811
+ - For a constant template parameter declared with a type that contains a
1812
+ placeholder type, `T` is the declared type of the constant template
1813
+ parameter and E is the corresponding template argument.
1814
+
1815
+ `T` shall not be an array type.
1816
+
1817
+ If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
1818
+ `auto`, the deduced type T' replacing `T` is determined using the rules
1819
+ for template argument deduction. If the initialization is
1820
+ copy-list-initialization, a declaration of `std::initializer_list` shall
1821
+ precede [[basic.lookup.general]] the *placeholder-type-specifier*.
1822
+ Obtain `P` from `T` by replacing the occurrence of *type-constraint*ₒₚₜ
1823
+ `auto` either with a new invented type template parameter `U` or, if the
1824
+ initialization is copy-list-initialization, with
1825
+ `std::initializer_list<U>`. Deduce a value for `U` using the rules of
1826
+ template argument deduction from a function call [[temp.deduct.call]],
1827
+ where `P` is a function template parameter type and the corresponding
1828
+ argument is E. If the deduction fails, the declaration is ill-formed.
1829
+ Otherwise, T' is obtained by substituting the deduced `U` into `P`.
1830
+
1831
+ [*Example 9*:
1832
+
1833
+ ``` cpp
1834
+ auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
1835
+ auto x2 = { 1, 2.0 }; // error: cannot deduce element type
1836
+ auto x3{ 1, 2 }; // error: not a single element
1837
+ auto x4 = { 3 }; // decltype(x4) is std::initializer_list<int>
1838
+ auto x5{ 3 }; // decltype(x5) is int
1839
+ ```
1840
+
1841
+ — *end example*]
1842
+
1843
+ [*Example 10*:
1844
+
1845
+ ``` cpp
1846
+ const auto &i = expr;
1847
+ ```
1848
+
1849
+ The type of `i` is the deduced type of the parameter `u` in the call
1850
+ `f(expr)` of the following invented function template:
1851
+
1852
+ ``` cpp
1853
+ template <class U> void f(const U& u);
1854
+ ```
1855
+
1856
+ — *end example*]
1857
+
1858
+ If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
1859
+ `decltype(auto)`, `T` shall be the placeholder alone. The type deduced
1860
+ for `T` is determined as described in  [[dcl.type.decltype]], as though
1861
+ E had been the operand of the `decltype`.
1862
+
1863
+ [*Example 11*:
1864
+
1865
+ ``` cpp
1866
+ int i;
1867
+ int&& f();
1868
+ auto x2a(i); // decltype(x2a) is int
1869
+ decltype(auto) x2d(i); // decltype(x2d) is int
1870
+ auto x3a = i; // decltype(x3a) is int
1871
+ decltype(auto) x3d = i; // decltype(x3d) is int
1872
+ auto x4a = (i); // decltype(x4a) is int
1873
+ decltype(auto) x4d = (i); // decltype(x4d) is int&
1874
+ auto x5a = f(); // decltype(x5a) is int
1875
+ decltype(auto) x5d = f(); // decltype(x5d) is int&&
1876
+ auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>
1877
+ decltype(auto) x6d = { 1, 2 }; // error: { 1, 2 } is not an expression
1878
+ auto *x7a = &i; // decltype(x7a) is int*
1879
+ decltype(auto)*x7d = &i; // error: declared type is not plain decltype(auto)
1880
+ auto f1(int x) -> decltype((x)) { return (x); } // return type is int&
1881
+ auto f2(int x) -> decltype(auto) { return (x); } // return type is int&&
1882
+ ```
1883
+
1884
+ — *end example*]
1885
+
1886
+ For a *placeholder-type-specifier* with a *type-constraint*, the
1887
+ immediately-declared constraint [[temp.param]] of the *type-constraint*
1888
+ for the type deduced for the placeholder shall be satisfied.
1889
+
1890
+ #### Deduced class template specialization types <a id="dcl.type.class.deduct">[[dcl.type.class.deduct]]</a>
1891
+
1892
+ If a placeholder for a deduced class type appears as a *decl-specifier*
1893
+ in the *decl-specifier-seq* of an initializing declaration [[dcl.init]]
1894
+ of a variable, the declared type of the variable shall be cv `T`, where
1895
+ `T` is the placeholder.
1896
+
1897
+ [*Example 1*:
1898
+
1899
+ ``` cpp
1900
+ template <class ...T> struct A {
1901
+ A(T...) {}
1902
+ };
1903
+ A x[29]{}; // error: no declarator operators allowed
1904
+ const A& y{}; // error: no declarator operators allowed
1905
+ ```
1906
+
1907
+ — *end example*]
1908
+
1909
+ The placeholder is replaced by the return type of the function selected
1910
+ by overload resolution for class template deduction
1911
+ [[over.match.class.deduct]]. If the *decl-specifier-seq* is followed by
1912
+ an *init-declarator-list* or *member-declarator-list* containing more
1913
+ than one *declarator*, the type that replaces the placeholder shall be
1914
+ the same in each deduction.
1915
+
1916
+ A placeholder for a deduced class type can also be used in the
1917
+ *type-specifier-seq* in the *new-type-id* or *type-id* of a
1918
+ *new-expression* [[expr.new]], as the *simple-type-specifier* in an
1919
+ explicit type conversion (functional notation) [[expr.type.conv]], or as
1920
+ the *type-specifier* in the *parameter-declaration* of a
1921
+ *template-parameter* [[temp.param]]. A placeholder for a deduced class
1922
+ type shall not appear in any other context.
1923
+
1924
+ [*Example 2*:
1925
+
1926
+ ``` cpp
1927
+ template<class T> struct container {
1928
+ container(T t) {}
1929
+ template<class Iter> container(Iter beg, Iter end);
1930
+ };
1931
+ template<class Iter>
1932
+ container(Iter b, Iter e) -> container<typename std::iterator_traits<Iter>::value_type>;
1933
+ std::vector<double> v = { ... };
1934
+
1935
+ container c(7); // OK, deduces int for T
1936
+ auto d = container(v.begin(), v.end()); // OK, deduces double for T
1937
+ container e{5, 6}; // error: int is not an iterator
1938
+ ```
1939
+
1940
+ — *end example*]
1941
+
1942
+ #### Type splicing <a id="dcl.type.splice">[[dcl.type.splice]]</a>
1943
+
1944
+ ``` bnf
1945
+ splice-type-specifier:
1946
+ typenameₒₚₜ splice-specifier
1947
+ typenameₒₚₜ splice-specialization-specifier
1948
+ ```
1949
+
1950
+ A *splice-specifier* or *splice-specialization-specifier* immediately
1951
+ followed by `::` is never interpreted as part of a
1952
+ *splice-type-specifier*. A *splice-specifier* or
1953
+ *splice-specialization-specifier* not preceded by `typename` is only
1954
+ interpreted as a *splice-type-specifier* within a type-only context
1955
+ [[temp.res.general]].
1956
+
1957
+ [*Example 1*:
1958
+
1959
+ ``` cpp
1960
+ template<std::meta::info R> void tfn() {
1961
+ typename [:R:]::type m; // OK, typename applies to the qualified name
1962
+ }
1963
+
1964
+ struct S { using type = int; };
1965
+ void fn() {
1966
+ [:^^S::type:] *var; // error: [:^^ S::type:] is an expression
1967
+ typename [:^^S::type:] *var; // OK, declares variable with type int*
1968
+ }
1969
+
1970
+ using alias = [:^^S::type:]; // OK, type-only context
1971
+ ```
1972
+
1973
+ — *end example*]
1974
+
1975
+ For a *splice-type-specifier* of the form `typename`ₒₚₜ
1976
+ *splice-specifier*, the *splice-specifier* shall designate a type, a
1977
+ class template, or an alias template. The *splice-type-specifier*
1978
+ designates the same entity as the *splice-specifier*.
1979
+
1980
+ For a *splice-type-specifier* of the form `typename`ₒₚₜ
1981
+ *splice-specialization-specifier*, the *splice-specifier* of the
1982
+ *splice-specialization-specifier* shall designate a template `T` that is
1983
+ either a class template or an alias template. The
1984
+ *splice-type-specifier* designates the specialization of `T`
1985
+ corresponding to the template argument list of the
1986
+ *splice-specialization-specifier*.
1987
+
1988
+ ## Declarators <a id="dcl.decl">[[dcl.decl]]</a>
1989
+
1990
+ ### General <a id="dcl.decl.general">[[dcl.decl.general]]</a>
1991
+
1992
+ A declarator declares a single variable, function, or type, within a
1993
+ declaration. The *init-declarator-list* appearing in a
1994
+ *simple-declaration* is a comma-separated sequence of declarators, each
1995
+ of which can have an initializer.
1996
+
1997
+ ``` bnf
1998
+ init-declarator-list:
1999
+ init-declarator
2000
+ init-declarator-list ',' init-declarator
2001
+ ```
2002
+
2003
+ ``` bnf
2004
+ init-declarator:
2005
+ declarator initializer
2006
+ declarator requires-clauseₒₚₜ function-contract-specifier-seqₒₚₜ
2007
+ ```
2008
+
2009
+ In all contexts, a *declarator* is interpreted as given below. Where an
2010
+ *abstract-declarator* can be used (or omitted) in place of a
2011
+ *declarator* [[dcl.fct]], [[except.pre]], it is as if a unique
2012
+ identifier were included in the appropriate place [[dcl.name]]. The
2013
+ preceding specifiers indicate the type, storage duration, linkage, or
2014
+ other properties of the entity or entities being declared. Each
2015
+ declarator specifies one entity and (optionally) names it and/or
2016
+ modifies the type of the specifiers with operators such as `*` (pointer
2017
+ to) and `()` (function returning).
2018
+
2019
+ [*Note 1*: An *init-declarator* can also specify an initializer
2020
+ [[dcl.init]]. — *end note*]
2021
+
2022
+ Each *init-declarator* or *member-declarator* in a declaration is
2023
+ analyzed separately as if it were in a declaration by itself.
2024
+
2025
+ [*Note 2*:
2026
+
2027
+ A declaration with several declarators is usually equivalent to the
2028
+ corresponding sequence of declarations each with a single declarator.
2029
+ That is,
2030
+
2031
+ ``` cpp
2032
+ T D1, D2, ... Dn;
2033
+ ```
2034
+
2035
+ is usually equivalent to
2036
+
2037
+ ``` cpp
2038
+ T D1; T D2; ... T Dn;
2039
+ ```
2040
+
2041
+ where `T` is a *decl-specifier-seq* and each `Di` is an
2042
+ *init-declarator* or *member-declarator*. One exception is when a name
2043
+ introduced by one of the *declarator*s hides a type name used by the
2044
+ *decl-specifier*s, so that when the same *decl-specifier*s are used in a
2045
+ subsequent declaration, they do not have the same meaning, as in
2046
+
2047
+ ``` cpp
2048
+ struct S { ... };
2049
+ S S, T; // declare two instances of struct S
2050
+ ```
2051
+
2052
+ which is not equivalent to
2053
+
2054
+ ``` cpp
2055
+ struct S { ... };
2056
+ S S;
2057
+ S T; // error
2058
+ ```
2059
+
2060
+ Another exception is when `T` is `auto` [[dcl.spec.auto]], for example:
2061
+
2062
+ ``` cpp
2063
+ auto i = 1, j = 2.0; // error: deduced types for i and j do not match
2064
+ ```
2065
+
2066
+ as opposed to
2067
+
2068
+ ``` cpp
2069
+ auto i = 1; // OK, i deduced to have type int
2070
+ auto j = 2.0; // OK, j deduced to have type double
2071
+ ```
2072
+
2073
+ — *end note*]
2074
+
2075
+ The optional *requires-clause* in an *init-declarator* or
2076
+ *member-declarator* shall be present only if the declarator declares a
2077
+ templated function [[temp.pre]]. When present after a declarator, the
2078
+ *requires-clause* is called the *trailing *requires-clause**. The
2079
+ trailing *requires-clause* introduces the *constraint-expression* that
2080
+ results from interpreting its *constraint-logical-or-expression* as a
2081
+ *constraint-expression*.
2082
+
2083
+ [*Example 1*:
2084
+
2085
+ ``` cpp
2086
+ void f1(int a) requires true; // error: non-templated function
2087
+ template<typename T>
2088
+ auto f2(T a) -> bool requires true; // OK
2089
+ template<typename T>
2090
+ auto f3(T a) requires true -> bool; // error: requires-clause precedes trailing-return-type
2091
+ void (*pf)() requires true; // error: constraint on a variable
2092
+ void g(int (*)() requires true); // error: constraint on a parameter-declaration
2093
+
2094
+ auto* p = new void(*)(char) requires true; // error: not a function declaration
2095
+ ```
2096
+
2097
+ — *end example*]
2098
+
2099
+ The optional *function-contract-specifier-seq* [[dcl.contract.func]] in
2100
+ an *init-declarator* shall be present only if the *declarator* declares
2101
+ a function.
2102
+
2103
+ Declarators have the syntax
2104
+
2105
+ ``` bnf
2106
+ declarator:
2107
+ ptr-declarator
2108
+ noptr-declarator parameters-and-qualifiers trailing-return-type
2109
+ ```
2110
+
2111
+ ``` bnf
2112
+ ptr-declarator:
2113
+ noptr-declarator
2114
+ ptr-operator ptr-declarator
2115
+ ```
2116
+
2117
+ ``` bnf
2118
+ noptr-declarator:
2119
+ declarator-id attribute-specifier-seqₒₚₜ
2120
+ noptr-declarator parameters-and-qualifiers
2121
+ noptr-declarator '[' constant-expressionₒₚₜ ']' attribute-specifier-seqₒₚₜ
2122
+ '(' ptr-declarator ')'
2123
+ ```
2124
+
2125
+ ``` bnf
2126
+ parameters-and-qualifiers:
2127
+ '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
2128
+ ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
2129
+ ```
2130
+
2131
+ ``` bnf
2132
+ trailing-return-type:
2133
+ '->' type-id
2134
+ ```
2135
+
2136
+ ``` bnf
2137
+ ptr-operator:
2138
+ '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ
2139
+ '&' attribute-specifier-seqₒₚₜ
2140
+ '&&' attribute-specifier-seqₒₚₜ
2141
+ nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ
2142
+ ```
2143
+
2144
+ ``` bnf
2145
+ cv-qualifier-seq:
2146
+ cv-qualifier cv-qualifier-seqₒₚₜ
2147
+ ```
2148
+
2149
+ ``` bnf
2150
+ cv-qualifier:
2151
+ const
2152
+ volatile
2153
+ ```
2154
+
2155
+ ``` bnf
2156
+ ref-qualifier:
2157
+ '&'
2158
+ '&&'
2159
+ ```
2160
+
2161
+ ``` bnf
2162
+ declarator-id:
2163
+ '...'ₒₚₜ id-expression
2164
+ ```
2165
+
2166
+ ### Type names <a id="dcl.name">[[dcl.name]]</a>
2167
+
2168
+ To specify type conversions explicitly, and as an argument of `sizeof`,
2169
+ `alignof`, `new`, or `typeid`, the name of a type shall be specified.
2170
+ This can be done with a *type-id* or *new-type-id* [[expr.new]], which
2171
+ is syntactically a declaration for a variable or function of that type
2172
+ that omits the name of the entity.
2173
+
2174
+ ``` bnf
2175
+ type-id:
2176
+ type-specifier-seq abstract-declaratorₒₚₜ
2177
+ ```
2178
+
2179
+ ``` bnf
2180
+ defining-type-id:
2181
+ defining-type-specifier-seq abstract-declaratorₒₚₜ
2182
+ ```
2183
+
2184
+ ``` bnf
2185
+ abstract-declarator:
2186
+ ptr-abstract-declarator
2187
+ noptr-abstract-declaratorₒₚₜ parameters-and-qualifiers trailing-return-type
2188
+ abstract-pack-declarator
2189
+ ```
2190
+
2191
+ ``` bnf
2192
+ ptr-abstract-declarator:
2193
+ noptr-abstract-declarator
2194
+ ptr-operator ptr-abstract-declaratorₒₚₜ
2195
+ ```
2196
+
2197
+ ``` bnf
2198
+ noptr-abstract-declarator:
2199
+ noptr-abstract-declaratorₒₚₜ parameters-and-qualifiers
2200
+ noptr-abstract-declaratorₒₚₜ '[' constant-expressionₒₚₜ ']' attribute-specifier-seqₒₚₜ
2201
+ '(' ptr-abstract-declarator ')'
2202
+ ```
2203
+
2204
+ ``` bnf
2205
+ abstract-pack-declarator:
2206
+ noptr-abstract-pack-declarator
2207
+ ptr-operator abstract-pack-declarator
2208
+ ```
2209
+
2210
+ ``` bnf
2211
+ noptr-abstract-pack-declarator:
2212
+ noptr-abstract-pack-declarator parameters-and-qualifiers
2213
+ '...'
2214
+ ```
2215
+
2216
+ It is possible to identify uniquely the location in the
2217
+ *abstract-declarator* where the identifier would appear if the
2218
+ construction were a declarator in a declaration. The named type is then
2219
+ the same as the type of the hypothetical identifier.
2220
+
2221
+ [*Example 1*:
2222
+
2223
+ ``` cpp
2224
+ int // int i
2225
+ int * // int *pi
2226
+ int *[3] // int *p[3]
2227
+ int (*)[3] // int (*p3i)[3]
2228
+ int *() // int *f()
2229
+ int (*)(double) // int (*pf)(double)
2230
+ ```
2231
+
2232
+ name respectively the types “`int`”, “pointer to `int`”, “array of 3
2233
+ pointers to `int`”, “pointer to array of 3 `int`”, “function of (no
2234
+ parameters) returning pointer to `int`”, and “pointer to a function of
2235
+ (`double`) returning `int`”.
2236
+
2237
+ — *end example*]
2238
+
2239
+ [*Note 1*: A type can also be named by a *typedef-name*, which is
2240
+ introduced by a typedef declaration or *alias-declaration*
2241
+ [[dcl.typedef]]. — *end note*]
2242
+
2243
+ ### Ambiguity resolution <a id="dcl.ambig.res">[[dcl.ambig.res]]</a>
2244
+
2245
+ The ambiguity arising from the similarity between a function-style cast
2246
+ and a declaration mentioned in  [[stmt.ambig]] can also occur in the
2247
+ context of a declaration. In that context, the choice is between an
2248
+ object declaration with a function-style cast as the initializer and a
2249
+ declaration involving a function declarator with a redundant set of
2250
+ parentheses around a parameter name. Just as for the ambiguities
2251
+ mentioned in  [[stmt.ambig]], the resolution is to consider any
2252
+ construct, such as the potential parameter declaration, that could
2253
+ possibly be a declaration to be a declaration. However, a construct that
2254
+ can syntactically be a *declaration* whose outermost *declarator* would
2255
+ match the grammar of a *declarator* with a *trailing-return-type* is a
2256
+ declaration only if it starts with `auto`.
2257
+
2258
+ [*Note 1*: A declaration can be explicitly disambiguated by adding
2259
+ parentheses around the argument. The ambiguity can be avoided by use of
2260
+ copy-initialization or list-initialization syntax, or by use of a
2261
+ non-function-style cast. — *end note*]
2262
+
2263
+ [*Example 1*:
2264
+
2265
+ ``` cpp
2266
+ struct S {
2267
+ S(int);
2268
+ };
2269
+ typedef struct BB { int C[2]; } *B, C;
2270
+
2271
+ void foo(double a) {
2272
+ S v(int(a)); // function declaration
2273
+ S w(int()); // function declaration
2274
+ S x((int(a))); // object declaration
2275
+ S y((int)a); // object declaration
2276
+ S z = int(a); // object declaration
2277
+ S a(B()->C); // object declaration
2278
+ S b(auto()->C); // function declaration
2279
+ }
2280
+ ```
2281
+
2282
+ — *end example*]
2283
+
2284
+ An ambiguity can arise from the similarity between a function-style cast
2285
+ and a *type-id*. The resolution is that any construct that could
2286
+ possibly be a *type-id* in its syntactic context shall be considered a
2287
+ *type-id*. However, a construct that can syntactically be a *type-id*
2288
+ whose outermost *abstract-declarator* would match the grammar of an
2289
+ *abstract-declarator* with a *trailing-return-type* is considered a
2290
+ *type-id* only if it starts with `auto`.
2291
+
2292
+ [*Example 2*:
2293
+
2294
+ ``` cpp
2295
+ template <class T> struct X {};
2296
+ template <int N> struct Y {};
2297
+ X<int()> a; // type-id
2298
+ X<int(1)> b; // expression (ill-formed)
2299
+ Y<int()> c; // type-id (ill-formed)
2300
+ Y<int(1)> d; // expression
2301
+
2302
+ void foo(signed char a) {
2303
+ sizeof(int()); // type-id (ill-formed)
2304
+ sizeof(int(a)); // expression
2305
+ sizeof(int(unsigned(a))); // type-id (ill-formed)
2306
+
2307
+ (int())+1; // type-id (ill-formed)
2308
+ (int(a))+1; // expression
2309
+ (int(unsigned(a)))+1; // type-id (ill-formed)
2310
+ }
2311
+
2312
+ typedef struct BB { int C[2]; } *B, C;
2313
+ void g() {
2314
+ sizeof(B()->C[1]); // OK, sizeof(expression)
2315
+ sizeof(auto()->C[1]); // error: sizeof of a function returning an array
2316
+ }
2317
+ ```
2318
+
2319
+ — *end example*]
2320
+
2321
+ Another ambiguity arises in a *parameter-declaration-clause* when a
2322
+ *type-name* is nested in parentheses. In this case, the choice is
2323
+ between the declaration of a parameter of type pointer to function and
2324
+ the declaration of a parameter with redundant parentheses around the
2325
+ *declarator-id*. The resolution is to consider the *type-name* as a
2326
+ *simple-type-specifier* rather than a *declarator-id*.
2327
+
2328
+ [*Example 3*:
2329
+
2330
+ ``` cpp
2331
+ class C { };
2332
+ void f(int(C)) { } // void f(int(*fp)(C c)) { }
2333
+ // not: void f(int C) { }
2334
+
2335
+ int g(C);
2336
+
2337
+ void foo() {
2338
+ f(1); // error: cannot convert 1 to function pointer
2339
+ f(g); // OK
2340
+ }
2341
+ ```
2342
+
2343
+ For another example,
2344
+
2345
+ ``` cpp
2346
+ class C { };
2347
+ void h(int *(C[10])); // void h(int *(*_fp)(C _parm[10]));
2348
+ // not: void h(int *C[10]);
2349
+ ```
2350
+
2351
+ — *end example*]
2352
+
2353
+ ### Meaning of declarators <a id="dcl.meaning">[[dcl.meaning]]</a>
2354
+
2355
+ #### General <a id="dcl.meaning.general">[[dcl.meaning.general]]</a>
2356
+
2357
+ A declarator contains exactly one *declarator-id*; it names the entity
2358
+ that is declared. If the *unqualified-id* occurring in a *declarator-id*
2359
+ is a *template-id*, the declarator shall appear in the *declaration* of
2360
+ a *template-declaration* [[temp.decls]], *explicit-specialization*
2361
+ [[temp.expl.spec]], or *explicit-instantiation* [[temp.explicit]].
2362
+
2363
+ [*Note 1*: An *unqualified-id* that is not an *identifier* is used to
2364
+ declare certain functions
2365
+ [[class.conv.fct]], [[class.dtor]], [[over.oper]], [[over.literal]]. — *end note*]
2366
+
2367
+ The optional *attribute-specifier-seq* following a *declarator-id*
2368
+ appertains to the entity that is declared.
2369
+
2370
+ If the declaration is a friend declaration:
2371
+
2372
+ - The *declarator* does not bind a name.
2373
+ - If the *id-expression* E in the *declarator-id* of the *declarator* is
2374
+ a *qualified-id* or a *template-id*:
2375
+ - If the friend declaration is not a template declaration, then in the
2376
+ lookup for the terminal name of E:
2377
+ - if the *unqualified-id* in E is a *template-id*, all function
2378
+ declarations are discarded;
2379
+ - otherwise, if the *declarator* corresponds [[basic.scope.scope]]
2380
+ to any declaration found of a non-template function, all function
2381
+ template declarations are discarded;
2382
+ - each remaining function template is replaced with the
2383
+ specialization chosen by deduction from the friend declaration
2384
+ [[temp.deduct.decl]] or discarded if deduction fails.
2385
+ - The *declarator* shall correspond to one or more declarations found
2386
+ by the lookup; they shall all have the same target scope, and the
2387
+ target scope of the *declarator* is that scope.
2388
+ - Otherwise, the terminal name of E is not looked up. The declaration’s
2389
+ target scope is the innermost enclosing namespace scope; if the
2390
+ declaration is contained by a block scope, the declaration shall
2391
+ correspond to a reachable [[module.reach]] declaration that inhabits
2392
+ the innermost block scope.
2393
+
2394
+ Otherwise:
2395
+
2396
+ - If the *id-expression* in the *declarator-id* of the *declarator* is a
2397
+ *qualified-id* Q, let S be its lookup context [[basic.lookup.qual]];
2398
+ the declaration shall inhabit a namespace scope.
2399
+ - Otherwise, let S be the entity associated with the scope inhabited by
2400
+ the *declarator*.
2401
+ - If the *declarator* declares an explicit instantiation or a partial or
2402
+ explicit specialization, the *declarator* does not bind a name. If it
2403
+ declares a class member, the terminal name of the *declarator-id* is
2404
+ not looked up; otherwise, only those lookup results that are nominable
2405
+ in S are considered when identifying any function template
2406
+ specialization being declared [[temp.deduct.decl]].
2407
+ \[*Example 1*:
2408
+ ``` cpp
2409
+ namespace N {
2410
+ inline namespace O {
2411
+ template<class T> void f(T); // #1
2412
+ template<class T> void g(T) {}
2413
+ }
2414
+ namespace P {
2415
+ template<class T> void f(T*); // #2, more specialized than #1
2416
+ template<class> int g;
2417
+ }
2418
+ using P::f,P::g;
2419
+ }
2420
+ template<> void N::f(int*) {} // OK, #2 is not nominable
2421
+ template void N::g(int); // error: lookup is ambiguous
2422
+ ```
2423
+
2424
+ — *end example*]
2425
+ - Otherwise, the terminal name of the *declarator-id* is not looked up.
2426
+ If it is a qualified name, the *declarator* shall correspond to one or
2427
+ more declarations nominable in S; all the declarations shall have the
2428
+ same target scope and the target scope of the *declarator* is that
2429
+ scope.
2430
+ \[*Example 2*:
2431
+ ``` cpp
2432
+ namespace Q {
2433
+ namespace V {
2434
+ void f();
2435
+ }
2436
+ void V::f() { ... } // OK
2437
+ void V::g() { ... } // error: g() is not yet a member of V
2438
+ namespace V {
2439
+ void g();
2440
+ }
2441
+ }
2442
+
2443
+ namespace R {
2444
+ void Q::V::g() { ... } // error: R doesn't enclose Q
2445
+ }
2446
+ ```
2447
+
2448
+ — *end example*]
2449
+ - If the declaration inhabits a block scope S and declares a function
2450
+ [[dcl.fct]] or uses the `extern` specifier, the declaration shall not
2451
+ be attached to a named module [[module.unit]]; its target scope is the
2452
+ innermost enclosing namespace scope, but the name is bound in S.
2453
+ \[*Example 3*:
2454
+ ``` cpp
2455
+ namespace X {
2456
+ void p() {
2457
+ q(); // error: q not yet declared
2458
+ extern void q(); // q is a member of namespace X
2459
+ extern void r(); // r is a member of namespace X
2460
+ }
2461
+
2462
+ void middle() {
2463
+ q(); // error: q not found
2464
+ }
2465
+
2466
+ void q() { ... } // definition of X::q
2467
+ }
2468
+
2469
+ void q() { ... } // some other, unrelated q
2470
+ void X::r() { ... } // error: r cannot be declared by qualified-id
2471
+ ```
2472
+
2473
+ — *end example*]
2474
+
2475
+ A `static`, `thread_local`, `extern`, `mutable`, `friend`, `inline`,
2476
+ `virtual`, `constexpr`, `consteval`, `constinit`, or `typedef` specifier
2477
+ or an *explicit-specifier* applies directly to each *declarator-id* in a
2478
+ declaration; the type specified for each *declarator-id* depends on both
2479
+ the *decl-specifier-seq* and its *declarator*.
2480
+
2481
+ Thus, (for each *declarator*) a declaration has the form
2482
+
2483
+ ``` cpp
2484
+ T D
2485
+ ```
2486
+
2487
+ where `T` is of the form *attribute-specifier-seq*ₒₚₜ
2488
+ *decl-specifier-seq* and `D` is a declarator. Following is a recursive
2489
+ procedure for determining the type specified for the contained
2490
+ *declarator-id* by such a declaration.
2491
+
2492
+ First, the *decl-specifier-seq* determines a type. In a declaration
2493
+
2494
+ ``` cpp
2495
+ T D
2496
+ ```
2497
+
2498
+ the *decl-specifier-seq* `T` determines the type `T`.
2499
+
2500
+ [*Example 4*:
2501
+
2502
+ In the declaration
2503
+
2504
+ ``` cpp
2505
+ int unsigned i;
2506
+ ```
2507
+
2508
+ the type specifiers `int` `unsigned` determine the type “`unsigned int`”
2509
+ [[dcl.type.simple]].
2510
+
2511
+ — *end example*]
2512
+
2513
+ In a declaration *attribute-specifier-seq*ₒₚₜ `T` `D` where `D` is an
2514
+ unadorned *declarator-id*, the type of the declared entity is “`T`”.
2515
+
2516
+ In a declaration `T` `D` where `D` has the form
2517
+
2518
+ ``` bnf
2519
+ '(' 'D1' ')'
2520
+ ```
2521
+
2522
+ the type of the contained *declarator-id* is the same as that of the
2523
+ contained *declarator-id* in the declaration
2524
+
2525
+ ``` cpp
2526
+ T D1
2527
+ ```
2528
+
2529
+ Parentheses do not alter the type of the embedded *declarator-id*, but
2530
+ they can alter the binding of complex declarators.
2531
+
2532
+ #### Pointers <a id="dcl.ptr">[[dcl.ptr]]</a>
2533
+
2534
+ In a declaration `T` `D` where `D` has the form
2535
+
2536
+ ``` bnf
2537
+ '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
2538
+ ```
2539
+
2540
+ and the type of the contained *declarator-id* in the declaration `T`
2541
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
2542
+ *declarator-id* in `D` is “*derived-declarator-type-list*
2543
+ *cv-qualifier-seq* pointer to `T`”. The *cv-qualifier*s apply to the
2544
+ pointer and not to the object pointed to. Similarly, the optional
2545
+ *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the pointer
2546
+ and not to the object pointed to.
2547
+
2548
+ [*Example 1*:
2549
+
2550
+ The declarations
2551
+
2552
+ ``` cpp
2553
+ const int ci = 10, *pc = &ci, *const cpc = pc, **ppc;
2554
+ int i, *p, *const cp = &i;
2555
+ ```
2556
+
2557
+ declare `ci`, a constant integer; `pc`, a pointer to a constant integer;
2558
+ `cpc`, a constant pointer to a constant integer; `ppc`, a pointer to a
2559
+ pointer to a constant integer; `i`, an integer; `p`, a pointer to
2560
+ integer; and `cp`, a constant pointer to integer. The value of `ci`,
2561
+ `cpc`, and `cp` cannot be changed after initialization. The value of
2562
+ `pc` can be changed, and so can the object pointed to by `cp`. Examples
2563
+ of some correct operations are
2564
+
2565
+ ``` cpp
2566
+ i = ci;
2567
+ *cp = ci;
2568
+ pc++;
2569
+ pc = cpc;
2570
+ pc = p;
2571
+ ppc = &pc;
2572
+ ```
2573
+
2574
+ Examples of ill-formed operations are
2575
+
2576
+ ``` cpp
2577
+ ci = 1; // error
2578
+ ci++; // error
2579
+ *pc = 2; // error
2580
+ cp = &ci; // error
2581
+ cpc++; // error
2582
+ p = pc; // error
2583
+ ppc = &p; // error
2584
+ ```
2585
+
2586
+ Each is unacceptable because it would either change the value of an
2587
+ object declared `const` or allow it to be changed through a
2588
+ cv-unqualified pointer later, for example:
2589
+
2590
+ ``` cpp
2591
+ *ppc = &ci; // OK, but would make p point to ci because of previous error
2592
+ *p = 5; // clobber ci
2593
+ ```
2594
+
2595
+ See also  [[expr.assign]] and  [[dcl.init]].
2596
+
2597
+ — *end example*]
2598
+
2599
+ [*Note 1*: Forming a pointer to reference type is ill-formed; see 
2600
+ [[dcl.ref]]. Forming a function pointer type is ill-formed if the
2601
+ function type has *cv-qualifier*s or a *ref-qualifier*; see 
2602
+ [[dcl.fct]]. Since the address of a bit-field [[class.bit]] cannot be
2603
+ taken, a pointer can never point to a bit-field. — *end note*]
2604
+
2605
+ #### References <a id="dcl.ref">[[dcl.ref]]</a>
2606
+
2607
+ In a declaration `T` `D` where `D` has either of the forms
2608
+
2609
+ ``` bnf
2610
+ '&' attribute-specifier-seqₒₚₜ 'D1'
2611
+ '&&' attribute-specifier-seqₒₚₜ 'D1'
2612
+ ```
2613
+
2614
+ and the type of the contained *declarator-id* in the declaration `T`
2615
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
2616
+ *declarator-id* in `D` is “*derived-declarator-type-list* reference to
2617
+ `T`”. The optional *attribute-specifier-seq* appertains to the reference
2618
+ type. Cv-qualified references are ill-formed except when the
2619
+ cv-qualifiers are introduced through the use of a *typedef-name*
2620
+ [[dcl.typedef]], [[temp.param]] or *decltype-specifier*
2621
+ [[dcl.type.decltype]], in which case the cv-qualifiers are ignored.
2622
+
2623
+ [*Example 1*:
2624
+
2625
+ ``` cpp
2626
+ typedef int& A;
2627
+ const A aref = 3; // error: lvalue reference to non-const initialized with rvalue
2628
+ ```
2629
+
2630
+ The type of `aref` is “lvalue reference to `int`”, not “lvalue reference
2631
+ to `const int`”.
2632
+
2633
+ — *end example*]
2634
+
2635
+ [*Note 1*: A reference can be thought of as a name of an
2636
+ object. — *end note*]
2637
+
2638
+ Forming the type “reference to cv `void`” is ill-formed.
2639
+
2640
+ A reference type that is declared using `&` is called an *lvalue
2641
+ reference*, and a reference type that is declared using `&&` is called
2642
+ an *rvalue reference*. Lvalue references and rvalue references are
2643
+ distinct types. Except where explicitly noted, they are semantically
2644
+ equivalent and commonly referred to as references.
2645
+
2646
+ [*Example 2*:
2647
+
2648
+ ``` cpp
2649
+ void f(double& a) { a += 3.14; }
2650
+ // ...
2651
+ double d = 0;
2652
+ f(d);
2653
+ ```
2654
+
2655
+ declares `a` to be a reference parameter of `f` so the call `f(d)` will
2656
+ add `3.14` to `d`.
2657
+
2658
+ ``` cpp
2659
+ int v[20];
2660
+ // ...
2661
+ int& g(int i) { return v[i]; }
2662
+ // ...
2663
+ g(3) = 7;
2664
+ ```
2665
+
2666
+ declares the function `g()` to return a reference to an integer so
2667
+ `g(3)=7` will assign `7` to the fourth element of the array `v`. For
2668
+ another example,
2669
+
2670
+ ``` cpp
2671
+ struct link {
2672
+ link* next;
2673
+ };
2674
+
2675
+ link* first;
2676
+
2677
+ void h(link*& p) { // p is a reference to pointer
2678
+ p->next = first;
2679
+ first = p;
2680
+ p = 0;
2681
+ }
2682
+
2683
+ void k() {
2684
+ link* q = new link;
2685
+ h(q);
2686
+ }
2687
+ ```
2688
+
2689
+ declares `p` to be a reference to a pointer to `link` so `h(q)` will
2690
+ leave `q` with the value zero. See also  [[dcl.init.ref]].
2691
+
2692
+ — *end example*]
2693
+
2694
+ It is unspecified whether or not a reference requires storage
2695
+ [[basic.stc]].
2696
+
2697
+ There shall be no references to references, no arrays of references, and
2698
+ no pointers to references. The declaration of a reference shall contain
2699
+ an *initializer* [[dcl.init.ref]] except when the declaration contains
2700
+ an explicit `extern` specifier [[dcl.stc]], is a class member
2701
+ [[class.mem]] declaration within a class definition, or is the
2702
+ declaration of a parameter or a return type [[dcl.fct]]; see 
2703
+ [[basic.def]].
2704
+
2705
+ Attempting to bind a reference to a function where the converted
2706
+ initializer is a glvalue whose type is not call-compatible [[expr.call]]
2707
+ with the type of the function’s definition results in undefined
2708
+ behavior. Attempting to bind a reference to an object where the
2709
+ converted initializer is a glvalue through which the object is not
2710
+ type-accessible [[basic.lval]] results in undefined behavior.
2711
+
2712
+ [*Note 2*: The object designated by such a glvalue can be outside its
2713
+ lifetime [[basic.life]]. Because a null pointer value or a pointer past
2714
+ the end of an object does not point to an object, a reference in a
2715
+ well-defined program cannot refer to such things; see 
2716
+ [[expr.unary.op]]. As described in  [[class.bit]], a reference cannot be
2717
+ bound directly to a bit-field. — *end note*]
2718
+
2719
+ The behavior of an evaluation of a reference
2720
+ [[expr.prim.id]], [[expr.ref]] that does not happen after
2721
+ [[intro.races]] the initialization of the reference is undefined.
2722
+
2723
+ [*Example 3*:
2724
+
2725
+ ``` cpp
2726
+ int &f(int&);
2727
+ int &g();
2728
+ extern int &ir3;
2729
+ int *ip = 0;
2730
+ int &ir1 = *ip; // undefined behavior: null pointer
2731
+ int &ir2 = f(ir3); // undefined behavior: ir3 not yet initialized
2732
+ int &ir3 = g();
2733
+ int &ir4 = f(ir4); // undefined behavior: ir4 used in its own initializer
2734
+
2735
+ char x alignas(int);
2736
+ int &ir5 = *reinterpret_cast<int *>(&x); // undefined behavior: initializer refers to char object
2737
+ ```
2738
+
2739
+ — *end example*]
2740
+
2741
+ If a *typedef-name* [[dcl.typedef]], [[temp.param]] or a
2742
+ *decltype-specifier* [[dcl.type.decltype]] denotes a type `TR` that is a
2743
+ reference to a type `T`, an attempt to create the type “lvalue reference
2744
+ to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
2745
+ to create the type “rvalue reference to cv `TR`” creates the type `TR`.
2746
+
2747
+ [*Note 3*: This rule is known as reference collapsing. — *end note*]
2748
+
2749
+ [*Example 4*:
2750
+
2751
+ ``` cpp
2752
+ int i;
2753
+ typedef int& LRI;
2754
+ typedef int&& RRI;
2755
+
2756
+ LRI& r1 = i; // r1 has the type int&
2757
+ const LRI& r2 = i; // r2 has the type int&
2758
+ const LRI&& r3 = i; // r3 has the type int&
2759
+
2760
+ RRI& r4 = i; // r4 has the type int&
2761
+ RRI&& r5 = 5; // r5 has the type int&&
2762
+
2763
+ decltype(r2)& r6 = i; // r6 has the type int&
2764
+ decltype(r2)&& r7 = i; // r7 has the type int&
2765
+ ```
2766
+
2767
+ — *end example*]
2768
+
2769
+ [*Note 4*: Forming a reference to function type is ill-formed if the
2770
+ function type has *cv-qualifier*s or a *ref-qualifier*; see 
2771
+ [[dcl.fct]]. — *end note*]
2772
+
2773
+ #### Pointers to members <a id="dcl.mptr">[[dcl.mptr]]</a>
2774
+
2775
+ The component names of a *ptr-operator* are those of its
2776
+ *nested-name-specifier*, if any.
2777
+
2778
+ In a declaration `T` `D` where `D` has the form
2779
+
2780
+ ``` bnf
2781
+ nested-name-specifier '*' attribute-specifier-seqₒₚₜ cv-qualifier-seqₒₚₜ 'D1'
2782
+ ```
2783
+
2784
+ and the *nested-name-specifier* designates a class, and the type of the
2785
+ contained *declarator-id* in the declaration `T` `D1` is
2786
+ “*derived-declarator-type-list* `T`”, the type of the *declarator-id* in
2787
+ `D` is “*derived-declarator-type-list* *cv-qualifier-seq* pointer to
2788
+ member of class *nested-name-specifier* of type `T`”. The optional
2789
+ *attribute-specifier-seq* [[dcl.attr.grammar]] appertains to the
2790
+ pointer-to-member. The *nested-name-specifier* shall not designate an
2791
+ anonymous union.
2792
+
2793
+ [*Example 1*:
2794
+
2795
+ ``` cpp
2796
+ struct X {
2797
+ void f(int);
2798
+ int a;
2799
+ };
2800
+ struct Y;
2801
+
2802
+ int X::* pmi = &X::a;
2803
+ void (X::* pmf)(int) = &X::f;
2804
+ double X::* pmd;
2805
+ char Y::* pmc;
2806
+ ```
2807
+
2808
+ declares `pmi`, `pmf`, `pmd` and `pmc` to be a pointer to a member of
2809
+ `X` of type `int`, a pointer to a member of `X` of type `void(int)`, a
2810
+ pointer to a member of `X` of type `double` and a pointer to a member of
2811
+ `Y` of type `char` respectively. The declaration of `pmd` is well-formed
2812
+ even though `X` has no members of type `double`. Similarly, the
2813
+ declaration of `pmc` is well-formed even though `Y` is an incomplete
2814
+ type. `pmi` and `pmf` can be used like this:
2815
+
2816
+ ``` cpp
2817
+ X obj;
2818
+ // ...
2819
+ obj.*pmi = 7; // assign 7 to an integer member of obj
2820
+ (obj.*pmf)(7); // call a function member of obj with the argument 7
2821
+ ```
2822
+
2823
+ — *end example*]
2824
+
2825
+ A pointer to member shall not point to a static member of a class
2826
+ [[class.static]], a member with reference type, or “cv `void`”.
2827
+
2828
+ [*Note 1*: See also  [[expr.unary]] and  [[expr.mptr.oper]]. The type
2829
+ “pointer to member” is distinct from the type “pointer”, that is, a
2830
+ pointer to member is declared only by the pointer-to-member declarator
2831
+ syntax, and never by the pointer declarator syntax. There is no
2832
+ “reference-to-member” type in C++. — *end note*]
2833
+
2834
+ #### Arrays <a id="dcl.array">[[dcl.array]]</a>
2835
+
2836
+ In a declaration `T` `D` where `D` has the form
2837
+
2838
+ ``` bnf
2839
+ 'D1' '[' constant-expressionₒₚₜ ']' attribute-specifier-seqₒₚₜ
2840
+ ```
2841
+
2842
+ and the type of the contained *declarator-id* in the declaration `T`
2843
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
2844
+ *declarator-id* in `D` is “*derived-declarator-type-list* array of `N`
2845
+ `T`”. The *constant-expression* shall be a converted constant expression
2846
+ of type `std::size_t` [[expr.const]]. Its value `N` specifies the *array
2847
+ bound*, i.e., the number of elements in the array; `N` shall be greater
2848
+ than zero.
2849
+
2850
+ In a declaration `T` `D` where `D` has the form
2851
+
2852
+ ``` bnf
2853
+ 'D1 [ ]' attribute-specifier-seqₒₚₜ
2854
+ ```
2855
+
2856
+ and the type of the contained *declarator-id* in the declaration `T`
2857
+ `D1` is “*derived-declarator-type-list* `T`”, the type of the
2858
+ *declarator-id* in `D` is “*derived-declarator-type-list* array of
2859
+ unknown bound of `T`”, except as specified below.
2860
+
2861
+ A type of the form “array of `N` `U`” or “array of unknown bound of `U`”
2862
+ is an *array type*. The optional *attribute-specifier-seq* appertains to
2863
+ the array type.
2864
+
2865
+ `U` is called the array *element type*; this type shall not be a
2866
+ reference type, a function type, an array of unknown bound, or
2867
+ cv `void`.
2868
+
2869
+ [*Note 1*: An array can be constructed from one of the fundamental
2870
+ types (except `void`), from a pointer, from a pointer to member, from a
2871
+ class, from an enumeration type, or from an array of known
2872
+ bound. — *end note*]
2873
+
2874
+ [*Example 1*:
2875
+
2876
+ ``` cpp
2877
+ float fa[17], *afp[17];
2878
+ ```
2879
+
2880
+ declares an array of `float` numbers and an array of pointers to `float`
2881
+ numbers.
2882
+
2883
+ — *end example*]
2884
+
2885
+ Any type of the form “*cv-qualifier-seq* array of `N` `U`” is adjusted
2886
+ to “array of `N` *cv-qualifier-seq* `U`”, and similarly for “array of
2887
+ unknown bound of `U`”.
2888
+
2889
+ [*Example 2*:
2890
+
2891
+ ``` cpp
2892
+ typedef int A[5], AA[2][3];
2893
+ typedef const A CA; // type is ``array of 5 const int''
2894
+ typedef const AA CAA; // type is ``array of 2 array of 3 const int''
2895
+ ```
2896
+
2897
+ — *end example*]
2898
+
2899
+ [*Note 2*: An “array of `N` *cv-qualifier-seq* `U`” has cv-qualified
2900
+ type; see  [[basic.type.qualifier]]. — *end note*]
2901
+
2902
+ An object of type “array of `N` `U`” consists of a contiguously
2903
+ allocated non-empty set of `N` subobjects of type `U`, known as the
2904
+ *elements* of the array, and numbered `0` to `N-1`.
2905
+
2906
+ In addition to declarations in which an incomplete object type is
2907
+ allowed, an array bound may be omitted in some cases in the declaration
2908
+ of a function parameter [[dcl.fct]]. An array bound may also be omitted
2909
+ when an object (but not a non-static data member) of array type is
2910
+ initialized and the declarator is followed by an initializer
2911
+ [[dcl.init]], [[class.mem]], [[expr.type.conv]], [[expr.new]]. In these
2912
+ cases, the array bound is calculated from the number of initial elements
2913
+ (say, `N`) supplied [[dcl.init.aggr]], and the type of the array is
2914
+ “array of `N` `U`”.
2915
+
2916
+ Furthermore, if there is a reachable declaration of the entity that
2917
+ specifies a bound and has the same host scope [[basic.scope.scope]], an
2918
+ omitted array bound is taken to be the same as in that earlier
2919
+ declaration, and similarly for the definition of a static data member of
2920
+ a class.
2921
+
2922
+ [*Example 3*:
2923
+
2924
+ ``` cpp
2925
+ extern int x[10];
2926
+ struct S {
2927
+ static int y[10];
2928
+ };
2929
+
2930
+ int x[]; // OK, bound is 10
2931
+ int S::y[]; // OK, bound is 10
2932
+
2933
+ void f() {
2934
+ extern int x[];
2935
+ int i = sizeof(x); // error: incomplete object type
2936
+ }
2937
+
2938
+ namespace A { extern int z[3]; }
2939
+ int A::z[] = {}; // OK, defines an array of 3 elements
2940
+ ```
2941
+
2942
+ — *end example*]
2943
+
2944
+ [*Note 3*:
2945
+
2946
+ When several “array of” specifications are adjacent, a multidimensional
2947
+ array type is created; only the first of the constant expressions that
2948
+ specify the bounds of the arrays can be omitted.
2949
+
2950
+ [*Example 4*:
2951
+
2952
+ ``` cpp
2953
+ int x3d[3][5][7];
2954
+ ```
2955
+
2956
+ declares an array of three elements, each of which is an array of five
2957
+ elements, each of which is an array of seven integers. The overall array
2958
+ can be viewed as a three-dimensional array of integers, with rank
2959
+ 3 × 5 × 7. Any of the expressions `x3d`, `x3d[i]`, `x3d[i][j]`,
2960
+ `x3d[i][j][k]` can reasonably appear in an expression. The expression
2961
+ `x3d[i]` is equivalent to `*(x3d + i)`; in that expression, `x3d` is
2962
+ subject to the array-to-pointer conversion [[conv.array]] and is first
2963
+ converted to a pointer to a 2-dimensional array with rank 5 × 7 that
2964
+ points to the first element of `x3d`. Then `i` is added, which on
2965
+ typical implementations involves multiplying `i` by the length of the
2966
+ object to which the pointer points, which is `sizeof(int)`× 5 × 7. The
2967
+ result of the addition and indirection is an lvalue denoting the `i`ᵗʰ
2968
+ array element of `x3d` (an array of five arrays of seven integers). If
2969
+ there is another subscript, the same argument applies again, so
2970
+ `x3d[i][j]` is an lvalue denoting the `j`ᵗʰ array element of the `i`ᵗʰ
2971
+ array element of `x3d` (an array of seven integers), and `x3d[i][j][k]`
2972
+ is an lvalue denoting the `k`ᵗʰ array element of the `j`ᵗʰ array element
2973
+ of the `i`ᵗʰ array element of `x3d` (an integer).
2974
+
2975
+ — *end example*]
2976
+
2977
+ The first subscript in the declaration helps determine the amount of
2978
+ storage consumed by an array but plays no other part in subscript
2979
+ calculations.
2980
+
2981
+ — *end note*]
2982
+
2983
+ [*Note 4*: Conversions affecting expressions of array type are
2984
+ described in  [[conv.array]]. — *end note*]
2985
+
2986
+ [*Note 5*: The subscript operator can be overloaded for a class
2987
+ [[over.sub]]. For the operator’s built-in meaning, see
2988
+ [[expr.sub]]. — *end note*]
2989
+
2990
+ #### Functions <a id="dcl.fct">[[dcl.fct]]</a>
2991
+
2992
+ In a declaration `T` `D` where `T` may be empty and `D` has the form
2993
+
2994
+ ``` bnf
2995
+ 'D1' '(' parameter-declaration-clause ')' cv-qualifier-seqₒₚₜ
2996
+ ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
2997
+ ```
2998
+
2999
+ a *derived-declarator-type-list* is determined as follows:
3000
+
3001
+ - If the *unqualified-id* of the *declarator-id* is a
3002
+ *conversion-function-id*, the *derived-declarator-type-list* is empty.
3003
+ - Otherwise, the *derived-declarator-type-list* is as appears in the
3004
+ type “*derived-declarator-type-list* `T`” of the contained
3005
+ *declarator-id* in the declaration `T` `D1`.
3006
+
3007
+ The declared return type `U` of the function type is determined as
3008
+ follows:
3009
+
3010
+ - If the *trailing-return-type* is present, `T` shall be the single
3011
+ *type-specifier* `auto`, and `U` is the type specified by the
3012
+ *trailing-return-type*.
3013
+ - Otherwise, if the declaration declares a conversion function, see 
3014
+ [[class.conv.fct]].
3015
+ - Otherwise, `U` is `T`.
3016
+
3017
+ The type of the *declarator-id* in `D` is
3018
+ “*derived-declarator-type-list* `noexcept`ₒₚₜ function of
3019
+ parameter-type-list *cv-qualifier-seq*ₒₚₜ *ref-qualifier*ₒₚₜ returning
3020
+ `U`”, where
3021
+
3022
+ - the parameter-type-list is derived from the
3023
+ *parameter-declaration-clause* as described below and
3024
+ - the optional `noexcept` is present if and only if the exception
3025
+ specification [[except.spec]] is non-throwing.
3026
+
3027
+ Such a type is a *function type*.[^2]
3028
+
3029
+ The optional *attribute-specifier-seq* appertains to the function type.
3030
+
3031
+ ``` bnf
3032
+ parameter-declaration-clause:
3033
+ '...'
3034
+ parameter-declaration-listₒₚₜ
3035
+ parameter-declaration-list ',' '...'
3036
+ parameter-declaration-list '...'
3037
+ ```
3038
+
3039
+ ``` bnf
3040
+ parameter-declaration-list:
3041
+ parameter-declaration
3042
+ parameter-declaration-list ',' parameter-declaration
3043
+ ```
3044
+
3045
+ ``` bnf
3046
+ parameter-declaration:
3047
+ attribute-specifier-seqₒₚₜ thisₒₚₜ decl-specifier-seq declarator
3048
+ attribute-specifier-seqₒₚₜ decl-specifier-seq declarator '=' initializer-clause
3049
+ attribute-specifier-seqₒₚₜ thisₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ
3050
+ attribute-specifier-seqₒₚₜ decl-specifier-seq abstract-declaratorₒₚₜ '=' initializer-clause
3051
+ ```
3052
+
3053
+ The optional *attribute-specifier-seq* in a *parameter-declaration*
3054
+ appertains to the parameter.
3055
+
3056
+ The *parameter-declaration-clause* determines the arguments that can be
3057
+ specified, and their processing, when the function is called.
3058
+
3059
+ [*Note 1*: The *parameter-declaration-clause* is used to convert the
3060
+ arguments specified on the function call; see 
3061
+ [[expr.call]]. — *end note*]
3062
+
3063
+ If the *parameter-declaration-clause* is empty, the function takes no
3064
+ arguments. A parameter list consisting of a single unnamed non-object
3065
+ parameter of non-dependent type `void` is equivalent to an empty
3066
+ parameter list. Except for this special case, a parameter shall not have
3067
+ type cv `void`. A parameter with volatile-qualified type is deprecated;
3068
+ see  [[depr.volatile.type]]. If the *parameter-declaration-clause*
3069
+ terminates with an ellipsis or a function parameter pack
3070
+ [[temp.variadic]], the number of arguments shall be equal to or greater
3071
+ than the number of parameters that do not have a default argument and
3072
+ are not function parameter packs. Where syntactically correct and where
3073
+ “`...`” is not part of an *abstract-declarator*, “`...`” is synonymous
3074
+ with “`, ...`”. A *parameter-declaration-clause* of the form
3075
+ *parameter-declaration-list* `...` is deprecated
3076
+ [[depr.ellipsis.comma]].
3077
+
3078
+ [*Example 1*:
3079
+
3080
+ The declaration
3081
+
3082
+ ``` cpp
3083
+ int printf(const char*, ...);
3084
+ ```
3085
+
3086
+ declares a function that can be called with varying numbers and types of
3087
+ arguments.
3088
+
3089
+ ``` cpp
3090
+ printf("hello world");
3091
+ printf("a=%d b=%d", a, b);
3092
+ ```
3093
+
3094
+ However, the first argument must be of a type that can be converted to a
3095
+ `const` `char*`.
3096
+
3097
+ — *end example*]
3098
+
3099
+ [*Note 2*: The standard header `<cstdarg>` contains a mechanism for
3100
+ accessing arguments passed using the ellipsis (see  [[expr.call]] and 
3101
+ [[support.runtime]]). — *end note*]
3102
+
3103
+ The type of a function is determined using the following rules. The type
3104
+ of each parameter (including function parameter packs) is determined
3105
+ from its own *parameter-declaration* [[dcl.decl]]. After determining the
3106
+ type of each parameter, any parameter of type “array of `T`” or of
3107
+ function type `T` is adjusted to be “pointer to `T`”. After producing
3108
+ the list of parameter types, any top-level *cv-qualifier*s modifying a
3109
+ parameter type are deleted when forming the function type. The resulting
3110
+ list of transformed parameter types and the presence or absence of the
3111
+ ellipsis or a function parameter pack is the function’s
3112
+ *parameter-type-list*.
3113
+
3114
+ [*Note 3*: This transformation does not affect the types of the
3115
+ parameters. For example, `int(*)(const int p, decltype(p)*)` and
3116
+ `int(*)(int, const int*)` are identical types. — *end note*]
3117
+
3118
+ [*Example 2*:
3119
+
3120
+ ``` cpp
3121
+ void f(char*); // #1
3122
+ void f(char[]) {} // defines #1
3123
+ void f(const char*) {} // OK, another overload
3124
+ void f(char *const) {} // error: redefines #1
3125
+
3126
+ void g(char(*)[2]); // #2
3127
+ void g(char[3][2]) {} // defines #2
3128
+ void g(char[3][3]) {} // OK, another overload
3129
+
3130
+ void h(int x(const int)); // #3
3131
+ void h(int (*)(int)) {} // defines #3
3132
+ ```
3133
+
3134
+ — *end example*]
3135
+
3136
+ An *explicit-object-parameter-declaration* is a *parameter-declaration*
3137
+ with a `this` specifier. An explicit-object-parameter-declaration shall
3138
+ appear only as the first *parameter-declaration* of a
3139
+ *parameter-declaration-list* of one of:
3140
+
3141
+ - a declaration of a member function or member function template
3142
+ [[class.mem]], or
3143
+ - an explicit instantiation [[temp.explicit]] or explicit specialization
3144
+ [[temp.expl.spec]] of a templated member function, or
3145
+ - a *lambda-declarator* [[expr.prim.lambda]].
3146
+
3147
+ A *member-declarator* with an explicit-object-parameter-declaration
3148
+ shall not include a *ref-qualifier* or a *cv-qualifier-seq* and shall
3149
+ not be declared `static` or `virtual`.
3150
+
3151
+ [*Example 3*:
3152
+
3153
+ ``` cpp
3154
+ struct C {
3155
+ void f(this C& self);
3156
+ template <typename Self> void g(this Self&& self, int);
3157
+
3158
+ void h(this C) const; // error: const not allowed here
3159
+ };
3160
+
3161
+ void test(C c) {
3162
+ c.f(); // OK, calls C::f
3163
+ c.g(42); // OK, calls C::g<C&>
3164
+ std::move(c).g(42); // OK, calls C::g<C>
3165
+ }
3166
+ ```
3167
+
3168
+ — *end example*]
3169
+
3170
+ A function parameter declared with an
3171
+ explicit-object-parameter-declaration is an *explicit object parameter*.
3172
+ An explicit object parameter shall not be a function parameter pack
3173
+ [[temp.variadic]]. An *explicit object member function* is a non-static
3174
+ member function with an explicit object parameter. An
3175
+ *implicit object member function* is a non-static member function
3176
+ without an explicit object parameter.
3177
+
3178
+ The *object parameter* of a non-static member function is either the
3179
+ explicit object parameter or the implicit object parameter
3180
+ [[over.match.funcs]].
3181
+
3182
+ A *non-object parameter* is a function parameter that is not the
3183
+ explicit object parameter. The *non-object-parameter-type-list* of a
3184
+ member function is the parameter-type-list of that function with the
3185
+ explicit object parameter, if any, omitted.
3186
+
3187
+ [*Note 4*: The non-object-parameter-type-list consists of the adjusted
3188
+ types of all the non-object parameters. — *end note*]
3189
+
3190
+ A function type with a *cv-qualifier-seq* or a *ref-qualifier*
3191
+ (including a type denoted by *typedef-name*
3192
+ [[dcl.typedef]], [[temp.param]]) shall appear only as:
3193
+
3194
+ - the function type for a non-static member function,
3195
+ - the function type to which a pointer to member refers,
3196
+ - the top-level function type of a function typedef declaration or
3197
+ *alias-declaration*,
3198
+ - the *type-id* in the default argument of a *type-parameter*
3199
+ [[temp.param]],
3200
+ - the *type-id* of a *template-argument* for a *type-parameter*
3201
+ [[temp.arg.type]], or
3202
+ - the operand of a *reflect-expression* [[expr.reflect]].
3203
+
3204
+ [*Example 4*:
3205
+
3206
+ ``` cpp
3207
+ typedef int FIC(int) const;
3208
+ FIC f; // error: does not declare a member function
3209
+ struct S {
3210
+ FIC f; // OK
3211
+ };
3212
+ FIC S::*pm = &S::f; // OK
3213
+ constexpr std::meta::info yeti = ^^void(int) const &; // OK
3214
+ ```
3215
+
3216
+ — *end example*]
3217
+
3218
+ The effect of a *cv-qualifier-seq* in a function declarator is not the
3219
+ same as adding cv-qualification on top of the function type. In the
3220
+ latter case, the cv-qualifiers are ignored.
3221
+
3222
+ [*Note 5*: A function type that has a *cv-qualifier-seq* is not a
3223
+ cv-qualified type; there are no cv-qualified function
3224
+ types. — *end note*]
3225
+
3226
+ [*Example 5*:
3227
+
3228
+ ``` cpp
3229
+ typedef void F();
3230
+ struct S {
3231
+ const F f; // OK, equivalent to: void f();
3232
+ };
3233
+ ```
3234
+
3235
+ — *end example*]
3236
+
3237
+ The return type, the parameter-type-list, the *ref-qualifier*, the
3238
+ *cv-qualifier-seq*, and the exception specification, but not the default
3239
+ arguments [[dcl.fct.default]] or the trailing *requires-clause*
3240
+ [[dcl.decl]], are part of the function type.
3241
+
3242
+ [*Note 6*: Function types are checked during the assignments and
3243
+ initializations of pointers to functions, references to functions, and
3244
+ pointers to member functions. — *end note*]
3245
+
3246
+ [*Example 6*:
3247
+
3248
+ The declaration
3249
+
3250
+ ``` cpp
3251
+ int fseek(FILE*, long, int);
3252
+ ```
3253
+
3254
+ declares a function taking three arguments of the specified types, and
3255
+ returning `int` [[dcl.type]].
3256
+
3257
+ — *end example*]
3258
+
3259
+ [*Note 7*: A single name can be used for several different functions in
3260
+ a single scope; this is function overloading [[over]]. — *end note*]
3261
+
3262
+ The return type shall be a non-array object type, a reference type, or
3263
+ cv `void`.
3264
+
3265
+ [*Note 8*: An array of placeholder type is considered an array
3266
+ type. — *end note*]
3267
+
3268
+ A volatile-qualified return type is deprecated; see 
3269
+ [[depr.volatile.type]].
3270
+
3271
+ Types shall not be defined in return or parameter types.
3272
+
3273
+ A typedef of function type may be used to declare a function but shall
3274
+ not be used to define a function [[dcl.fct.def]].
3275
+
3276
+ [*Example 7*:
3277
+
3278
+ ``` cpp
3279
+ typedef void F();
3280
+ F fv; // OK, equivalent to void fv();
3281
+ F fv { } // error
3282
+ void fv() { } // OK, definition of fv
3283
+ ```
3284
+
3285
+ — *end example*]
3286
+
3287
+ An identifier can optionally be provided as a parameter name; if present
3288
+ in a function definition [[dcl.fct.def]], it names a parameter.
3289
+
3290
+ [*Note 9*: In particular, parameter names are also optional in function
3291
+ definitions and names used for a parameter in different declarations and
3292
+ the definition of a function need not be the same. — *end note*]
3293
+
3294
+ [*Example 8*:
3295
+
3296
+ The declaration
3297
+
3298
+ ``` cpp
3299
+ int i,
3300
+ *pi,
3301
+ f(),
3302
+ *fpi(int),
3303
+ (*pif)(const char*, const char*),
3304
+ (*fpif(int))(int);
3305
+ ```
3306
+
3307
+ declares an integer `i`, a pointer `pi` to an integer, a function `f`
3308
+ taking no arguments and returning an integer, a function `fpi` taking an
3309
+ integer argument and returning a pointer to an integer, a pointer `pif`
3310
+ to a function which takes two pointers to constant characters and
3311
+ returns an integer, a function `fpif` taking an integer argument and
3312
+ returning a pointer to a function that takes an integer argument and
3313
+ returns an integer. It is especially useful to compare `fpi` and `pif`.
3314
+ The binding of `*fpi(int)` is `*(fpi(int))`, so the declaration
3315
+ suggests, and the same construction in an expression requires, the
3316
+ calling of a function `fpi`, and then using indirection through the
3317
+ (pointer) result to yield an integer. In the declarator
3318
+ `(*pif)(const char*, const char*)`, the extra parentheses are necessary
3319
+ to indicate that indirection through a pointer to a function yields a
3320
+ function, which is then called.
3321
+
3322
+ — *end example*]
3323
+
3324
+ [*Note 10*:
3325
+
3326
+ Typedefs and *trailing-return-type*s are sometimes convenient when the
3327
+ return type of a function is complex. For example, the function `fpif`
3328
+ above can be declared
3329
+
3330
+ ``` cpp
3331
+ typedef int IFUNC(int);
3332
+ IFUNC* fpif(int);
3333
+ ```
3334
+
3335
+ or
3336
+
3337
+ ``` cpp
3338
+ auto fpif(int)->int(*)(int);
3339
+ ```
3340
+
3341
+ A *trailing-return-type* is most useful for a type that would be more
3342
+ complicated to specify before the *declarator-id*:
3343
+
3344
+ ``` cpp
3345
+ template <class T, class U> auto add(T t, U u) -> decltype(t + u);
3346
+ ```
3347
+
3348
+ rather than
3349
+
3350
+ ``` cpp
3351
+ template <class T, class U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
3352
+ ```
3353
+
3354
+ — *end note*]
3355
+
3356
+ A *non-template function* is a function that is not a function template
3357
+ specialization.
3358
+
3359
+ [*Note 11*: A function template is not a function. — *end note*]
3360
+
3361
+ An *abbreviated function template* is a function declaration that has
3362
+ one or more generic parameter type placeholders [[dcl.spec.auto]]. An
3363
+ abbreviated function template is equivalent to a function template
3364
+ [[temp.fct]] whose *template-parameter-list* includes one invented
3365
+ *type-parameter* for each generic parameter type placeholder of the
3366
+ function declaration, in order of appearance. For a
3367
+ *placeholder-type-specifier* of the form `auto`, the invented parameter
3368
+ is an unconstrained *type-parameter*. For a *placeholder-type-specifier*
3369
+ of the form *type-constraint* `auto`, the invented parameter is a
3370
+ *type-parameter* with that *type-constraint*. The invented
3371
+ *type-parameter* declares a template parameter pack if the corresponding
3372
+ *parameter-declaration* declares a function parameter pack. If the
3373
+ placeholder contains `decltype(auto)`, the program is ill-formed. The
3374
+ adjusted function parameters of an abbreviated function template are
3375
+ derived from the *parameter-declaration-clause* by replacing each
3376
+ occurrence of a placeholder with the name of the corresponding invented
3377
+ *type-parameter*.
3378
+
3379
+ [*Example 9*:
3380
+
3381
+ ``` cpp
3382
+ template<typename T> concept C1 = /* ... */;
3383
+ template<typename T> concept C2 = /* ... */;
3384
+ template<typename... Ts> concept C3 = /* ... */;
3385
+
3386
+ void g1(const C1 auto*, C2 auto&);
3387
+ void g2(C1 auto&...);
3388
+ void g3(C3 auto...);
3389
+ void g4(C3 auto);
3390
+ ```
3391
+
3392
+ The declarations above are functionally equivalent (but not equivalent)
3393
+ to their respective declarations below:
3394
+
3395
+ ``` cpp
3396
+ template<C1 T, C2 U> void g1(const T*, U&);
3397
+ template<C1... Ts> void g2(Ts&...);
3398
+ template<C3... Ts> void g3(Ts...);
3399
+ template<C3 T> void g4(T);
3400
+ ```
3401
+
3402
+ Abbreviated function templates can be specialized like all function
3403
+ templates.
3404
+
3405
+ ``` cpp
3406
+ template<> void g1<int>(const int*, const double&); // OK, specialization of g1<int, const double>
3407
+ ```
3408
+
3409
+ — *end example*]
3410
+
3411
+ An abbreviated function template can have a *template-head*. The
3412
+ invented *type-parameter*s are appended to the *template-parameter-list*
3413
+ after the explicitly declared *template-parameter*s.
3414
+
3415
+ [*Example 10*:
3416
+
3417
+ ``` cpp
3418
+ template<typename> concept C = /* ... */;
3419
+
3420
+ template <typename T, C U>
3421
+ void g(T x, U y, C auto z);
3422
+ ```
3423
+
3424
+ This is functionally equivalent to each of the following two
3425
+ declarations.
3426
+
3427
+ ``` cpp
3428
+ template<typename T, C U, C W>
3429
+ void g(T x, U y, W z);
3430
+
3431
+ template<typename T, typename U, typename W>
3432
+ requires C<U> && C<W>
3433
+ void g(T x, U y, W z);
3434
+ ```
3435
+
3436
+ — *end example*]
3437
+
3438
+ A function declaration at block scope shall not declare an abbreviated
3439
+ function template.
3440
+
3441
+ A *declarator-id* or *abstract-declarator* containing an ellipsis shall
3442
+ only be used in a *parameter-declaration*. When it is part of a
3443
+ *parameter-declaration-clause*, the *parameter-declaration* declares a
3444
+ function parameter pack [[temp.variadic]]. Otherwise, the
3445
+ *parameter-declaration* is part of a *template-parameter-list* and
3446
+ declares a template parameter pack; see  [[temp.param]]. A function
3447
+ parameter pack is a pack expansion [[temp.variadic]].
3448
+
3449
+ [*Example 11*:
3450
+
3451
+ ``` cpp
3452
+ template<typename... T> void f(T (* ...t)(int, int));
3453
+
3454
+ int add(int, int);
3455
+ float subtract(int, int);
3456
+
3457
+ void g() {
3458
+ f(add, subtract);
3459
+ }
3460
+ ```
3461
+
3462
+ — *end example*]
3463
+
3464
+ There is a syntactic ambiguity when an ellipsis occurs at the end of a
3465
+ *parameter-declaration-clause* without a preceding comma. In this case,
3466
+ the ellipsis is parsed as part of the *abstract-declarator* if the type
3467
+ of the parameter either names a template parameter pack that has not
3468
+ been expanded or contains `auto`; otherwise, it is parsed as part of the
3469
+ *parameter-declaration-clause*.[^3]
3470
+
3471
+ #### Default arguments <a id="dcl.fct.default">[[dcl.fct.default]]</a>
3472
+
3473
+ If an *initializer-clause* is specified in a *parameter-declaration*
3474
+ this *initializer-clause* is used as a default argument.
3475
+
3476
+ [*Note 1*: Default arguments will be used in calls where trailing
3477
+ arguments are missing [[expr.call]]. — *end note*]
3478
+
3479
+ [*Example 1*:
3480
+
3481
+ The declaration
3482
+
3483
+ ``` cpp
3484
+ void point(int = 3, int = 4);
3485
+ ```
3486
+
3487
+ declares a function that can be called with zero, one, or two arguments
3488
+ of type `int`. It can be called in any of these ways:
3489
+
3490
+ ``` cpp
3491
+ point(1,2); point(1); point();
3492
+ ```
3493
+
3494
+ The last two calls are equivalent to `point(1,4)` and `point(3,4)`,
3495
+ respectively.
3496
+
3497
+ — *end example*]
3498
+
3499
+ A default argument shall be specified only in the
3500
+ *parameter-declaration-clause* of a function declaration or
3501
+ *lambda-declarator* or in a *template-parameter* [[temp.param]]. A
3502
+ default argument shall not be specified for a template parameter pack or
3503
+ a function parameter pack. If it is specified in a
3504
+ *parameter-declaration-clause*, it shall not occur within a *declarator*
3505
+ or *abstract-declarator* of a *parameter-declaration*.[^4]
3506
+
3507
+ For non-template functions, default arguments can be added in later
3508
+ declarations of a function that have the same host scope. Declarations
3509
+ that have different host scopes have completely distinct sets of default
3510
+ arguments. That is, declarations in inner scopes do not acquire default
3511
+ arguments from declarations in outer scopes, and vice versa. In a given
3512
+ function declaration, each parameter subsequent to a parameter with a
3513
+ default argument shall have a default argument supplied in this or a
3514
+ previous declaration, unless the parameter was expanded from a parameter
3515
+ pack, or shall be a function parameter pack.
3516
+
3517
+ [*Note 2*: A default argument cannot be redefined by a later
3518
+ declaration (not even to the same value)
3519
+ [[basic.def.odr]]. — *end note*]
3520
+
3521
+ [*Example 2*:
3522
+
3523
+ ``` cpp
3524
+ void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow
3525
+ // a parameter with a default argument
3526
+ void f(int, int);
3527
+ void f(int, int = 7);
3528
+ void h() {
3529
+ f(3); // OK, calls f(3, 7)
3530
+ void f(int = 1, int); // error: does not use default from surrounding scope
3531
+ }
3532
+ void m() {
3533
+ void f(int, int); // has no defaults
3534
+ f(4); // error: wrong number of arguments
3535
+ void f(int, int = 5); // OK
3536
+ f(4); // OK, calls f(4, 5);
3537
+ void f(int, int = 5); // error: cannot redefine, even to same value
3538
+ }
3539
+ void n() {
3540
+ f(6); // OK, calls f(6, 7)
3541
+ }
3542
+ template<class ... T> struct C {
3543
+ void f(int n = 0, T...);
3544
+ };
3545
+ C<int> c; // OK, instantiates declaration void C::f(int n = 0, int)
3546
+ ```
3547
+
3548
+ — *end example*]
3549
+
3550
+ For a given inline function defined in different translation units, the
3551
+ accumulated sets of default arguments at the end of the translation
3552
+ units shall be the same; no diagnostic is required. If a friend
3553
+ declaration D specifies a default argument expression, that declaration
3554
+ shall be a definition and there shall be no other declaration of the
3555
+ function or function template which is reachable from D or from which D
3556
+ is reachable.
3557
+
3558
+ The default argument has the same semantic constraints as the
3559
+ initializer in a declaration of a variable of the parameter type, using
3560
+ the copy-initialization semantics [[dcl.init]]. The names in the default
3561
+ argument are looked up, and the semantic constraints are checked, at the
3562
+ point where the default argument appears, except that an immediate
3563
+ invocation [[expr.const]] that is a potentially-evaluated subexpression
3564
+ [[intro.execution]] of the *initializer-clause* in a
3565
+ *parameter-declaration* is neither evaluated nor checked for whether it
3566
+ is a constant expression at that point. Name lookup and checking of
3567
+ semantic constraints for default arguments of templated functions are
3568
+ performed as described in  [[temp.inst]].
3569
+
3570
+ [*Example 3*:
3571
+
3572
+ In the following code, `g` will be called with the value `f(2)`:
3573
+
3574
+ ``` cpp
3575
+ int a = 1;
3576
+ int f(int);
3577
+ int g(int x = f(a)); // default argument: f(::a)
3578
+
3579
+ void h() {
3580
+ a = 2;
3581
+ {
3582
+ int a = 3;
3583
+ g(); // g(f(::a))
3584
+ }
3585
+ }
3586
+ ```
3587
+
3588
+ — *end example*]
3589
+
3590
+ [*Note 3*: A default argument is a complete-class context
3591
+ [[class.mem]]. Access checking applies to names in default arguments as
3592
+ described in [[class.access]]. — *end note*]
3593
+
3594
+ Except for member functions of templated classes, the default arguments
3595
+ in a member function definition that appears outside of the class
3596
+ definition are added to the set of default arguments provided by the
3597
+ member function declaration in the class definition; the program is
3598
+ ill-formed if a default constructor [[class.default.ctor]], copy or move
3599
+ constructor [[class.copy.ctor]], or copy or move assignment operator
3600
+ [[class.copy.assign]] is so declared. Default arguments for a member
3601
+ function of a templated class shall be specified on the initial
3602
+ declaration of the member function within the templated class.
3603
+
3604
+ [*Example 4*:
3605
+
3606
+ ``` cpp
3607
+ class C {
3608
+ void f(int i = 3);
3609
+ void g(int i, int j = 99);
3610
+ };
3611
+
3612
+ void C::f(int i = 3) {} // error: default argument already specified in class scope
3613
+ void C::g(int i = 88, int j) {} // in this translation unit, C::g can be called with no arguments
3614
+ ```
3615
+
3616
+ — *end example*]
3617
+
3618
+ [*Note 4*: A local variable cannot be odr-used [[term.odr.use]] in a
3619
+ default argument. — *end note*]
3620
+
3621
+ [*Example 5*:
3622
+
3623
+ ``` cpp
3624
+ void f() {
3625
+ int i;
3626
+ extern void g(int x = i); // error
3627
+ extern void h(int x = sizeof(i)); // OK
3628
+ // ...
3629
+ }
3630
+ ```
3631
+
3632
+ — *end example*]
3633
+
3634
+ [*Note 5*:
3635
+
3636
+ The keyword `this` cannot appear in a default argument of a member
3637
+ function; see  [[expr.prim.this]].
3638
+
3639
+ [*Example 6*:
3640
+
3641
+ ``` cpp
3642
+ class A {
3643
+ void f(A* p = this) { } // error
3644
+ };
3645
+ ```
3646
+
3647
+ — *end example*]
3648
+
3649
+ — *end note*]
3650
+
3651
+ A default argument is evaluated each time the function is called with no
3652
+ argument for the corresponding parameter. A parameter shall not appear
3653
+ as a potentially-evaluated expression in a default argument.
3654
+
3655
+ [*Note 6*: Parameters of a function declared before a default argument
3656
+ are in scope and can hide namespace and class member
3657
+ names. — *end note*]
3658
+
3659
+ [*Example 7*:
3660
+
3661
+ ``` cpp
3662
+ int a;
3663
+ int f(int a, int b = a); // error: parameter a used as default argument
3664
+ typedef int I;
3665
+ int g(float I, int b = I(2)); // error: parameter I found
3666
+ int h(int a, int b = sizeof(a)); // OK, unevaluated operand[term.unevaluated.operand]
3667
+ ```
3668
+
3669
+ — *end example*]
3670
+
3671
+ A non-static member shall not be designated in a default argument unless
3672
+
3673
+ - it is designated by the *id-expression* or *splice-expression* of a
3674
+ class member access expression [[expr.ref]],
3675
+ - it is designated by an expression used to form a pointer to member
3676
+ [[expr.unary.op]], or
3677
+ - it appears as the operand of a *reflect-expression* [[expr.reflect]].
3678
+
3679
+ [*Example 8*:
3680
+
3681
+ The declaration of `X::mem1()` in the following example is ill-formed
3682
+ because no object is supplied for the non-static member `X::a` used as
3683
+ an initializer.
3684
+
3685
+ ``` cpp
3686
+ int b;
3687
+ class X {
3688
+ int a;
3689
+ int mem1(int i = a); // error: non-static member a used as default argument
3690
+ int mem2(int i = b); // OK, use X::b
3691
+ consteval void mem3(std::meta::info r = ^^a) {} // OK
3692
+ int mem4(int i = [:^^a:]); // error: non-static member a designated in default argument
3693
+ static int b;
3694
+ };
3695
+ ```
3696
+
3697
+ The declaration of `X::mem2()` is meaningful, however, since no object
3698
+ is needed to access the static member `X::b`. Classes, objects, and
3699
+ members are described in [[class]].
3700
+
3701
+ — *end example*]
3702
+
3703
+ A default argument is not part of the type of a function.
3704
+
3705
+ [*Example 9*:
3706
+
3707
+ ``` cpp
3708
+ int f(int = 0);
3709
+
3710
+ void h() {
3711
+ int j = f(1);
3712
+ int k = f(); // OK, means f(0)
3713
+ }
3714
+
3715
+ int (*p1)(int) = &f;
3716
+ int (*p2)() = &f; // error: type mismatch
3717
+ ```
3718
+
3719
+ — *end example*]
3720
+
3721
+ [*Note 7*: When an overload set contains a declaration of a function
3722
+ whose host scope is S, any default argument associated with any
3723
+ reachable declaration whose host scope is S is available to the call
3724
+ [[over.match.viable]]. — *end note*]
3725
+
3726
+ [*Note 8*: The candidate might have been found through a
3727
+ *using-declarator* from which the declaration that provides the default
3728
+ argument is not reachable. — *end note*]
3729
+
3730
+ A virtual function call [[class.virtual]] uses the default arguments in
3731
+ the declaration of the virtual function determined by the static type of
3732
+ the pointer or reference denoting the object. An overriding function in
3733
+ a derived class does not acquire default arguments from the function it
3734
+ overrides.
3735
+
3736
+ [*Example 10*:
3737
+
3738
+ ``` cpp
3739
+ struct A {
3740
+ virtual void f(int a = 7);
3741
+ };
3742
+ struct B : public A {
3743
+ void f(int a);
3744
+ };
3745
+ void m() {
3746
+ B* pb = new B;
3747
+ A* pa = pb;
3748
+ pa->f(); // OK, calls pa->B::f(7)
3749
+ pb->f(); // error: wrong number of arguments for B::f()
3750
+ }
3751
+ ```
3752
+
3753
+ — *end example*]
3754
+
3755
+ ## Function contract specifiers <a id="dcl.contract">[[dcl.contract]]</a>
3756
+
3757
+ ### General <a id="dcl.contract.func">[[dcl.contract.func]]</a>
3758
+
3759
+ ``` bnf
3760
+ function-contract-specifier-seq:
3761
+ function-contract-specifier function-contract-specifier-seqₒₚₜ
3762
+ ```
3763
+
3764
+ ``` bnf
3765
+ function-contract-specifier:
3766
+ precondition-specifier
3767
+ postcondition-specifier
3768
+ ```
3769
+
3770
+ ``` bnf
3771
+ precondition-specifier:
3772
+ 'pre' attribute-specifier-seqₒₚₜ '(' conditional-expression ')'
3773
+ ```
3774
+
3775
+ ``` bnf
3776
+ postcondition-specifier:
3777
+ 'post' attribute-specifier-seqₒₚₜ '(' result-name-introducerₒₚₜ conditional-expression ')'
3778
+ ```
3779
+
3780
+ A *function contract assertion* is a contract assertion
3781
+ [[basic.contract.general]] associated with a function. A
3782
+ *precondition-specifier* introduces a *precondition assertion*, which is
3783
+ a function contract assertion associated with entering a function. A
3784
+ *postcondition-specifier* introduces a *postcondition assertion*, which
3785
+ is a function contract assertion associated with exiting a function
3786
+ normally.
3787
+
3788
+ [*Note 1*: A postcondition assertion is not associated with exiting a
3789
+ function in any other fashion, such as via an exception [[expr.throw]]
3790
+ or via a call to `longjmp` [[csetjmp.syn]]. — *end note*]
3791
+
3792
+ The predicate [[basic.contract.general]] of a function contract
3793
+ assertion is its *conditional-expression* contextually converted to
3794
+ `bool`.
3795
+
3796
+ Each *function-contract-specifier* of a
3797
+ *function-contract-specifier-seq* (if any) of an unspecified first
3798
+ declaration [[basic.def]] of a function introduces a corresponding
3799
+ function contract assertion for that function. The optional
3800
+ *attribute-specifier-seq* following `pre` or `post` appertains to the
3801
+ introduced contract assertion.
3802
+
3803
+ [*Note 2*: The *function-contract-specifier-seq* of a
3804
+ *lambda-declarator* applies to the function call operator or operator
3805
+ template of the corresponding closure type
3806
+ [[expr.prim.lambda.closure]]. — *end note*]
3807
+
3808
+ A declaration D of a function or function template *f* that is not a
3809
+ first declaration shall have either no *function-contract-specifier-seq*
3810
+ or the same *function-contract-specifier-seq* (see below) as any first
3811
+ declaration F reachable from D. If D and F are in different translation
3812
+ units, a diagnostic is required only if D is attached to a named module.
3813
+ If a declaration F₁ is a first declaration of `f` in one translation
3814
+ unit and a declaration F₂ is a first declaration of `f` in another
3815
+ translation unit, F₁ and F₂ shall specify the same
3816
+ *function-contract-specifier-seq*, no diagnostic required.
3817
+
3818
+ A *function-contract-specifier-seq* S₁ is the same as a
3819
+ *function-contract-specifier-seq* S₂ if S₁ and S₂ consist of the same
3820
+ *function-contract-specifier*s in the same order. A
3821
+ *function-contract-specifier* C₁ on a function declaration D₁ is the
3822
+ same as a *function-contract-specifier* C₂ on a function declaration D₂
3823
+ if
3824
+
3825
+ - their predicates P₁ and P₂ would satisfy the one-definition rule
3826
+ [[basic.def.odr]] if placed in function definitions on the
3827
+ declarations D₁ and D₂, respectively, except for
3828
+ - renaming of the parameters of *f*,
3829
+ - renaming of template parameters of a template enclosing **, and
3830
+ - renaming of the result binding [[dcl.contract.res]], if any,
3831
+
3832
+ and, if D₁ and D₂ are in different translation units, corresponding
3833
+ entities defined within each predicate behave as if there is a single
3834
+ entity with a single definition, and
3835
+ - both C₁ and C₂ specify a *result-name-introducer* or neither do.
3836
+
3837
+ If this condition is not met solely due to the comparison of two
3838
+ *lambda-expression*s that are contained within P₁ and P₂, no diagnostic
3839
+ is required.
3840
+
3841
+ [*Note 3*: Equivalent *function-contract-specifier-seq*s apply to all
3842
+ uses and definitions of a function across all translation
3843
+ units. — *end note*]
3844
+
3845
+ [*Example 1*:
3846
+
3847
+ ``` cpp
3848
+ bool b1, b2;
3849
+
3850
+ void f() pre (b1) pre ([]{ return b2; }());
3851
+ void f(); // OK, function-contract-specifiers omitted
3852
+ void f() pre (b1) pre ([]{ return b2; }()); // error: closures have different types.
3853
+ void f() pre (b1); // error: function-contract-specifiers only partially repeated
3854
+
3855
+ int g() post(r : b1);
3856
+ int g() post(b1); // error: mismatched result-name-introducer presence
3857
+
3858
+ namespace N {
3859
+ void h() pre (b1);
3860
+ bool b1;
3861
+ void h() pre (b1); // error: function-contract-specifiers differ according to
3862
+ // the one-definition rule[basic.def.odr].
3863
+ }
3864
+ ```
3865
+
3866
+ — *end example*]
3867
+
3868
+ A virtual function [[class.virtual]], a deleted function
3869
+ [[dcl.fct.def.delete]], or a function defaulted on its first declaration
3870
+ [[dcl.fct.def.default]] shall not have a
3871
+ *function-contract-specifier-seq*.
3872
+
3873
+ If the predicate of a postcondition assertion of a function *f* odr-uses
3874
+ [[basic.def.odr]] a non-reference parameter of *f*, that parameter and
3875
+ the corresponding parameter on all declarations of *f* shall have
3876
+ `const` type.
3877
+
3878
+ [*Note 4*:
3879
+
3880
+ This requirement applies even to declarations that do not specify the
3881
+ *postcondition-specifier*. Parameters with array or function type will
3882
+ decay to non-`const` types even if a `const` qualifier is present.
3883
+
3884
+ [*Example 2*:
3885
+
3886
+ ``` cpp
3887
+ int f(const int i[10])
3888
+ post(r : r == i[0]); // error: i has type const int * (not int* const).
3889
+ ```
3890
+
3891
+ — *end example*]
3892
+
3893
+ — *end note*]
3894
+
3895
+ [*Note 5*: The function contract assertions of a function are evaluated
3896
+ even when invoked indirectly, such as through a pointer to function or a
3897
+ pointer to member function. A pointer to function, pointer to member
3898
+ function, or function type alias cannot have a
3899
+ *function-contract-specifier-seq* associated directly with
3900
+ it. — *end note*]
3901
+
3902
+ The function contract assertions of a function are considered to be
3903
+ *needed* [[temp.inst]] when
3904
+
3905
+ - the function is odr-used [[basic.def.odr]] or
3906
+ - the function is defined.
3907
+
3908
+ [*Note 6*:
3909
+
3910
+ Overload resolution does not consider *function-contract-specifier*s
3911
+ [[temp.deduct]], [[temp.inst]].
3912
+
3913
+ [*Example 3*:
3914
+
3915
+ ``` cpp
3916
+ template <typename T> void f(T t) pre( t == "" );
3917
+ template <typename T> void f(T&& t);
3918
+ void g()
3919
+ {
3920
+ f(5); // error: ambiguous
3921
+ }
3922
+ ```
3923
+
3924
+ — *end example*]
3925
+
3926
+ — *end note*]
3927
+
3928
+ ### Referring to the result object <a id="dcl.contract.res">[[dcl.contract.res]]</a>
3929
+
3930
+ ``` bnf
3931
+ attributed-identifier:
3932
+ identifier attribute-specifier-seqₒₚₜ
3933
+ ```
3934
+
3935
+ ``` bnf
3936
+ result-name-introducer:
3937
+ attributed-identifier ':'
3938
+ ```
3939
+
3940
+ The *result-name-introducer* of a *postcondition-specifier* is a
3941
+ declaration. The *result-name-introducer* introduces the *identifier* as
3942
+ the name of a *result binding* of the associated function. If a
3943
+ postcondition assertion has a *result-name-introducer* and the return
3944
+ type of the function is cv `void`, the program is ill-formed. A result
3945
+ binding denotes the object or reference returned by invocation of that
3946
+ function. The type of a result binding is the return type of its
3947
+ associated function. The optional *attribute-specifier-seq* of the
3948
+ *attributed-identifier* in the *result-name-introducer* appertains to
3949
+ the result binding so introduced.
3950
+
3951
+ [*Note 1*: An *id-expression* that names a result binding is a `const`
3952
+ lvalue [[expr.prim.id.unqual]]. — *end note*]
3953
+
3954
+ [*Example 1*:
3955
+
3956
+ ``` cpp
3957
+ int f()
3958
+ post(r : r == 1)
3959
+ {
3960
+ return 1;
3961
+ }
3962
+ int i = f(); // Postcondition check succeeds.
3963
+ ```
3964
+
3965
+ — *end example*]
3966
+
3967
+ [*Example 2*:
3968
+
3969
+ ``` cpp
3970
+ struct A {};
3971
+ struct B {
3972
+ B() {}
3973
+ B(const B&) {}
3974
+ };
3975
+
3976
+ template <typename T>
3977
+ T f(T* const ptr)
3978
+ post(r: &r == ptr)
3979
+ {
3980
+ return {};
3981
+ }
3982
+
3983
+ int main() {
3984
+ A a = f(&a); // The postcondition check can fail if the implementation introduces
3985
+ // a temporary for the return value[class.temporary].
3986
+ B b = f(&b); // The postcondition check succeeds, no temporary is introduced.
3987
+ }
3988
+ ```
3989
+
3990
+ — *end example*]
3991
+
3992
+ When the declared return type of a non-templated function contains a
3993
+ placeholder type, a *postcondition-specifier* with a
3994
+ *result-name-introducer* shall be present only on a definition.
3995
+
3996
+ [*Example 3*:
3997
+
3998
+ ``` cpp
3999
+ auto g(auto&)
4000
+ post (r: r >= 0); // OK, g is a template.
4001
+
4002
+ auto h()
4003
+ post (r: r >= 0); // error: cannot name the return value
4004
+
4005
+ auto k()
4006
+ post (r: r >= 0) // OK
4007
+ {
4008
+ return 0;
4009
+ }
4010
+ ```
4011
+
4012
+ — *end example*]
4013
+
4014
+ ## Initializers <a id="dcl.init">[[dcl.init]]</a>
4015
+
4016
+ ### General <a id="dcl.init.general">[[dcl.init.general]]</a>
4017
+
4018
+ The process of initialization described in [[dcl.init]] applies to all
4019
+ initializations regardless of syntactic context, including the
4020
+ initialization of a function parameter [[expr.call]], the initialization
4021
+ of a return value [[stmt.return]], or when an initializer follows a
4022
+ declarator.
4023
+
4024
+ ``` bnf
4025
+ initializer:
4026
+ brace-or-equal-initializer
4027
+ '(' expression-list ')'
4028
+ ```
4029
+
4030
+ ``` bnf
4031
+ brace-or-equal-initializer:
4032
+ '=' initializer-clause
4033
+ braced-init-list
4034
+ ```
4035
+
4036
+ ``` bnf
4037
+ initializer-clause:
4038
+ assignment-expression
4039
+ braced-init-list
4040
+ ```
4041
+
4042
+ ``` bnf
4043
+ braced-init-list:
4044
+ '{' initializer-list ','ₒₚₜ '}'
4045
+ '{' designated-initializer-list ','ₒₚₜ '}'
4046
+ '{' '}'
4047
+ ```
4048
+
4049
+ ``` bnf
4050
+ initializer-list:
4051
+ initializer-clause '...'ₒₚₜ
4052
+ initializer-list ',' initializer-clause '...'ₒₚₜ
4053
+ ```
4054
+
4055
+ ``` bnf
4056
+ designated-initializer-list:
4057
+ designated-initializer-clause
4058
+ designated-initializer-list ',' designated-initializer-clause
4059
+ ```
4060
+
4061
+ ``` bnf
4062
+ designated-initializer-clause:
4063
+ designator brace-or-equal-initializer
4064
+ ```
4065
+
4066
+ ``` bnf
4067
+ designator:
4068
+ '.' identifier
4069
+ ```
4070
+
4071
+ ``` bnf
4072
+ expr-or-braced-init-list:
4073
+ expression
4074
+ braced-init-list
4075
+ ```
4076
+
4077
+ [*Note 1*: The rules in [[dcl.init]] apply even if the grammar permits
4078
+ only the *brace-or-equal-initializer* form of *initializer* in a given
4079
+ context. — *end note*]
4080
+
4081
+ Except for objects declared with the `constexpr` specifier, for which
4082
+ see  [[dcl.constexpr]], an *initializer* in the definition of a variable
4083
+ can consist of arbitrary expressions involving literals and previously
4084
+ declared variables and functions, regardless of the variable’s storage
4085
+ duration.
4086
+
4087
+ [*Example 1*:
4088
+
4089
+ ``` cpp
4090
+ int f(int);
4091
+ int a = 2;
4092
+ int b = f(a);
4093
+ int c(b);
4094
+ ```
4095
+
4096
+ — *end example*]
4097
+
4098
+ [*Note 2*: Default arguments are more restricted; see 
4099
+ [[dcl.fct.default]]. — *end note*]
4100
+
4101
+ [*Note 3*: The order of initialization of variables with static storage
4102
+ duration is described in  [[basic.start]] and 
4103
+ [[stmt.dcl]]. — *end note*]
4104
+
4105
+ A declaration D of a variable with linkage shall not have an
4106
+ *initializer* if D inhabits a block scope.
4107
+
4108
+ To *zero-initialize* an object or reference of type `T` means:
4109
+
4110
+ - if `T` is `std::meta::info`, the object is initialized to a null
4111
+ reflection value;
4112
+ - if `T` is any other scalar type [[term.scalar.type]], the object is
4113
+ initialized to the value obtained by converting the integer literal
4114
+ `0` (zero) to `T`;[^5]
4115
+ - if `T` is a (possibly cv-qualified) non-union class type, its padding
4116
+ bits [[term.padding.bits]] are initialized to zero bits and each
4117
+ non-static data member, each non-virtual base class subobject, and, if
4118
+ the object is not a base class subobject, each virtual base class
4119
+ subobject is zero-initialized;
4120
+ - if `T` is a (possibly cv-qualified) union type, its padding bits
4121
+ [[term.padding.bits]] are initialized to zero bits and the object’s
4122
+ first non-static named data member is zero-initialized;
4123
+ - if `T` is an array type, each element is zero-initialized;
4124
+ - if `T` is a reference type, no initialization is performed.
4125
+
4126
+ To *default-initialize* an object of type `T` means:
4127
+
4128
+ - If `T` is a (possibly cv-qualified) class type [[class]], constructors
4129
+ are considered. The applicable constructors are enumerated
4130
+ [[over.match.ctor]], and the best one for the *initializer* `()` is
4131
+ chosen through overload resolution [[over.match]]. The constructor
4132
+ thus selected is called, with an empty argument list, to initialize
4133
+ the object.
4134
+ - If `T` is an array type, the semantic constraints of
4135
+ default-initializing a hypothetical element shall be met and each
4136
+ element is default-initialized.
4137
+ - If `T` is `std::meta::info`, the object is zero-initialized.
4138
+ - Otherwise, no initialization is performed.
4139
+
4140
+ A class type `T` is *const-default-constructible* if
4141
+ default-initialization of `T` would invoke a user-provided constructor
4142
+ of `T` (not inherited from a base class) or if
4143
+
4144
+ - each direct non-variant non-static data member `M` of `T` has a
4145
+ default member initializer or, if `M` is of class type `X` (or array
4146
+ thereof), `X` is const-default-constructible,
4147
+ - if `T` is a union with at least one non-static data member, exactly
4148
+ one variant member has a default member initializer,
4149
+ - if `T` is not a union, for each anonymous union member with at least
4150
+ one non-static data member (if any), exactly one non-static data
4151
+ member has a default member initializer, and
4152
+ - each potentially constructed base class of `T` is
4153
+ const-default-constructible.
4154
+
4155
+ If a program calls for the default-initialization of an object of a
4156
+ const-qualified type `T`, `T` shall be `std::meta::info` or a
4157
+ const-default-constructible class type, or array thereof.
4158
+
4159
+ To *value-initialize* an object of type `T` means:
4160
+
4161
+ - If `T` is a (possibly cv-qualified) class type [[class]], then let `C`
4162
+ be the constructor selected to default-initialize the object, if any.
4163
+ If `C` is not user-provided, the object is first zero-initialized. In
4164
+ all cases, the object is then default-initialized.
4165
+ - If `T` is an array type, the semantic constraints of
4166
+ value-initializing a hypothetical element shall be met and each
4167
+ element is value-initialized.
4168
+ - Otherwise, the object is zero-initialized.
4169
+
4170
+ A program that calls for default-initialization or value-initialization
4171
+ of an entity of reference type is ill-formed.
4172
+
4173
+ [*Note 4*: For every object with static storage duration, static
4174
+ initialization [[basic.start.static]] is performed at program startup
4175
+ before any other initialization takes place. In some cases, additional
4176
+ initialization is done later. — *end note*]
4177
+
4178
+ If no initializer is specified for an object, the object is
4179
+ default-initialized.
4180
+
4181
+ If the entity being initialized does not have class or array type, the
4182
+ *expression-list* in a parenthesized initializer shall be a single
4183
+ expression.
4184
+
4185
+ The initialization that occurs in the `=` form of a
4186
+ *brace-or-equal-initializer* or *condition* [[stmt.select]], as well as
4187
+ in argument passing, function return, throwing an exception
4188
+ [[except.throw]], handling an exception [[except.handle]], and aggregate
4189
+ member initialization other than by a *designated-initializer-clause*
4190
+ [[dcl.init.aggr]], is called *copy-initialization*.
4191
+
4192
+ [*Note 5*: Copy-initialization can invoke a move
4193
+ [[class.copy.ctor]]. — *end note*]
4194
+
4195
+ The initialization that occurs
4196
+
4197
+ - for an *initializer* that is a parenthesized *expression-list* or a
4198
+ *braced-init-list*,
4199
+ - for a *new-initializer* [[expr.new]],
4200
+ - in a `static_cast` expression [[expr.static.cast]],
4201
+ - in a functional notation type conversion [[expr.type.conv]], and
4202
+ - in the *braced-init-list* form of a *condition*
4203
+
4204
+ is called *direct-initialization*.
4205
+
4206
+ The semantics of initializers are as follows. The *destination type* is
4207
+ the cv-unqualified type of the object or reference being initialized and
4208
+ the *source type* is the type of the initializer expression. If the
4209
+ initializer is not a single (possibly parenthesized) expression, the
4210
+ source type is not defined.
4211
+
4212
+ - If the initializer is a (non-parenthesized) *braced-init-list* or is
4213
+ `=` *braced-init-list*, the object or reference is list-initialized
4214
+ [[dcl.init.list]].
4215
+ - If the destination type is a reference type, see  [[dcl.init.ref]].
4216
+ - If the destination type is an array of characters, an array of
4217
+ `char8_t`, an array of `char16_t`, an array of `char32_t`, or an array
4218
+ of `wchar_t`, and the initializer is a *string-literal*, see 
4219
+ [[dcl.init.string]].
4220
+ - If the initializer is `()`, the object is value-initialized.
4221
+ \[*Note 6*:
4222
+ Since `()` is not permitted by the syntax for *initializer*,
4223
+ ``` cpp
4224
+ X a();
4225
+ ```
4226
+
4227
+ is not the declaration of an object of class `X`, but the declaration
4228
+ of a function taking no arguments and returning an `X`. The form `()`
4229
+ can appear in certain other initialization contexts
4230
+ [[expr.new]], [[expr.type.conv]], [[class.base.init]].
4231
+ — *end note*]
4232
+ - Otherwise, if the destination type is an array, the object is
4233
+ initialized as follows. The *initializer* shall be of the form `(`
4234
+ *expression-list* `)`. Let x₁, …, xₖ be the elements of the
4235
+ *expression-list*. If the destination type is an array of unknown
4236
+ bound, it is defined as having k elements. Let n denote the array size
4237
+ after this potential adjustment. If k is greater than n, the program
4238
+ is ill-formed. Otherwise, the iᵗʰ array element is copy-initialized
4239
+ with xᵢ for each 1 ≤ i ≤ k, and value-initialized for each k < i ≤ n.
4240
+ For each 1 ≤ i < j ≤ n, every value computation and side effect
4241
+ associated with the initialization of the iᵗʰ element of the array is
4242
+ sequenced before those associated with the initialization of the jᵗʰ
4243
+ element.
4244
+ - Otherwise, if the destination type is a class type:
4245
+ - If the initializer expression is a prvalue and the cv-unqualified
4246
+ version of the source type is the same as the destination type, the
4247
+ initializer expression is used to initialize the destination object.
4248
+ \[*Example 2*: `T x = T(T(T()));` value-initializes `x`
4249
+ [[basic.lval]], [[expr.type.conv]]. — *end example*]
4250
+ - Otherwise, if the initialization is direct-initialization, or if it
4251
+ is copy-initialization where the cv-unqualified version of the
4252
+ source type is the same as or is derived from the class of the
4253
+ destination type, constructors are considered. The applicable
4254
+ constructors are enumerated [[over.match.ctor]], and the best one is
4255
+ chosen through overload resolution [[over.match]]. Then:
4256
+ - If overload resolution is successful, the selected constructor is
4257
+ called to initialize the object, with the initializer expression
4258
+ or *expression-list* as its argument(s).
4259
+ - Otherwise, if no constructor is viable, the destination type is an
4260
+ aggregate class, and the initializer is a parenthesized
4261
+ *expression-list*, the object is initialized as follows. Let e₁,
4262
+ …, eₙ be the elements of the aggregate [[dcl.init.aggr]]. Let x₁,
4263
+ …, xₖ be the elements of the *expression-list*. If k is greater
4264
+ than n, the program is ill-formed. The element eᵢ is
4265
+ copy-initialized with xᵢ for 1 ≤ i ≤ k. The remaining elements are
4266
+ initialized with their default member initializers, if any, and
4267
+ otherwise are value-initialized. For each 1 ≤ i < j ≤ n, every
4268
+ value computation and side effect associated with the
4269
+ initialization of eᵢ is sequenced before those associated with the
4270
+ initialization of eⱼ.
4271
+ \[*Note 7*:
4272
+ By contrast with direct-list-initialization, narrowing conversions
4273
+ [[dcl.init.list]] can appear, designators are not permitted, a
4274
+ temporary object bound to a reference does not have its lifetime
4275
+ extended [[class.temporary]], and there is no brace elision.
4276
+ \[*Example 3*:
4277
+ ``` cpp
4278
+ struct A {
4279
+ int a;
4280
+ int&& r;
4281
+ };
4282
+
4283
+ int f();
4284
+ int n = 10;
4285
+
4286
+ A a1{1, f()}; // OK, lifetime is extended
4287
+ A a2(1, f()); // well-formed, but dangling reference
4288
+ A a3{1.0, 1}; // error: narrowing conversion
4289
+ A a4(1.0, 1); // well-formed, but dangling reference
4290
+ A a5(1.0, std::move(n)); // OK
4291
+ ```
4292
+
4293
+ — *end example*]
4294
+ — *end note*]
4295
+ - Otherwise, the initialization is ill-formed.
4296
+ - Otherwise (i.e., for the remaining copy-initialization cases),
4297
+ user-defined conversions that can convert from the source type to
4298
+ the destination type or (when a conversion function is used) to a
4299
+ derived class thereof are enumerated as described in 
4300
+ [[over.match.copy]], and the best one is chosen through overload
4301
+ resolution [[over.match]]. If the conversion cannot be done or is
4302
+ ambiguous, the initialization is ill-formed. The function selected
4303
+ is called with the initializer expression as its argument; if the
4304
+ function is a constructor, the call is a prvalue of the
4305
+ cv-unqualified version of the destination type whose result object
4306
+ is initialized by the constructor. The call is used to
4307
+ direct-initialize, according to the rules above, the object that is
4308
+ the destination of the copy-initialization.
4309
+ - Otherwise, if the source type is a (possibly cv-qualified) class type,
4310
+ conversion functions are considered. The applicable conversion
4311
+ functions are enumerated [[over.match.conv]], and the best one is
4312
+ chosen through overload resolution [[over.match]]. The user-defined
4313
+ conversion so selected is called to convert the initializer expression
4314
+ into the object being initialized. If the conversion cannot be done or
4315
+ is ambiguous, the initialization is ill-formed.
4316
+ - Otherwise, if the initialization is direct-initialization, the source
4317
+ type is `std::nullptr_t`, and the destination type is `bool`, the
4318
+ initial value of the object being initialized is `false`.
4319
+ - Otherwise, the initial value of the object being initialized is the
4320
+ (possibly converted) value of the initializer expression. A standard
4321
+ conversion sequence [[conv]] is used to convert the initializer
4322
+ expression to a prvalue of the destination type; no user-defined
4323
+ conversions are considered. If the conversion cannot be done, the
4324
+ initialization is ill-formed. When initializing a bit-field with a
4325
+ value that it cannot represent, the resulting value of the bit-field
4326
+ is *implementation-defined*.
4327
+ \[*Note 8*:
4328
+ An expression of type “*cv1* `T`” can initialize an object of type
4329
+ “*cv2* `T`” independently of the cv-qualifiers *cv1* and *cv2*.
4330
+ ``` cpp
4331
+ int a;
4332
+ const int b = a;
4333
+ int c = b;
4334
+ ```
4335
+
4336
+ — *end note*]
4337
+
4338
+ An immediate invocation [[expr.const]] that is not evaluated where it
4339
+ appears [[dcl.fct.default]], [[class.mem.general]] is evaluated and
4340
+ checked for whether it is a constant expression at the point where the
4341
+ enclosing *initializer* is used in a function call, a constructor
4342
+ definition, or an aggregate initialization.
4343
+
4344
+ An *initializer-clause* followed by an ellipsis is a pack expansion
4345
+ [[temp.variadic]].
4346
+
4347
+ Initialization includes the evaluation of all subexpressions of each
4348
+ *initializer-clause* of the initializer (possibly nested within
4349
+ *braced-init-list*s) and the creation of any temporary objects for
4350
+ function arguments or return values [[class.temporary]].
4351
+
4352
+ If the initializer is a parenthesized *expression-list*, the expressions
4353
+ are evaluated in the order specified for function calls [[expr.call]].
4354
+
4355
+ The same *identifier* shall not appear in multiple *designator*s of a
4356
+ *designated-initializer-list*.
4357
+
4358
+ An object whose initialization has completed is deemed to be
4359
+ constructed, even if the object is of non-class type or no constructor
4360
+ of the object’s class is invoked for the initialization.
4361
+
4362
+ [*Note 9*: Such an object might have been value-initialized or
4363
+ initialized by aggregate initialization [[dcl.init.aggr]] or by an
4364
+ inherited constructor [[class.inhctor.init]]. — *end note*]
4365
+
4366
+ Destroying an object of class type invokes the destructor of the class.
4367
+ Destroying a scalar type has no effect other than ending the lifetime of
4368
+ the object [[basic.life]]. Destroying an array destroys each element in
4369
+ reverse subscript order.
4370
+
4371
+ A declaration that specifies the initialization of a variable, whether
4372
+ from an explicit initializer or by default-initialization, is called the
4373
+ *initializing declaration* of that variable.
4374
+
4375
+ [*Note 10*: In most cases this is the defining declaration
4376
+ [[basic.def]] of the variable, but the initializing declaration of a
4377
+ non-inline static data member [[class.static.data]] can be the
4378
+ declaration within the class definition and not the definition (if any)
4379
+ outside it. — *end note*]
4380
+
4381
+ ### Aggregates <a id="dcl.init.aggr">[[dcl.init.aggr]]</a>
4382
+
4383
+ An *aggregate* is an array or a class [[class]] with
4384
+
4385
+ - no user-declared or inherited constructors [[class.ctor]],
4386
+ - no private or protected direct non-static data members
4387
+ [[class.access]],
4388
+ - no private or protected direct base classes [[class.access.base]], and
4389
+ - no virtual functions [[class.virtual]] or virtual base classes
4390
+ [[class.mi]].
4391
+
4392
+ [*Note 1*: Aggregate initialization does not allow accessing protected
4393
+ and private base class’ members, including constructors. — *end note*]
4394
+
4395
+ The *elements* of an aggregate are:
4396
+
4397
+ - for an array, the array elements in increasing subscript order, or
4398
+ - for a class, the direct base classes in declaration order, followed by
4399
+ the direct non-static data members [[class.mem]] that are not members
4400
+ of an anonymous union, in declaration order.
4401
+
4402
+ When an aggregate is initialized by an initializer list as specified in 
4403
+ [[dcl.init.list]], the elements of the initializer list are taken as
4404
+ initializers for the elements of the aggregate. The *explicitly
4405
+ initialized elements* of the aggregate are determined as follows:
4406
+
4407
+ - If the initializer list is a brace-enclosed
4408
+ *designated-initializer-list*, the aggregate shall be of class type,
4409
+ the *identifier* in each *designator* shall name a direct non-static
4410
+ data member of the class, and the explicitly initialized elements of
4411
+ the aggregate are the elements that are, or contain, those members.
4412
+ - If the initializer list is a brace-enclosed *initializer-list*, the
4413
+ explicitly initialized elements of the aggregate are those for which
4414
+ an element of the initializer list appertains to the aggregate element
4415
+ or to a subobject thereof (see below).
4416
+ - Otherwise, the initializer list must be `{}`, and there are no
4417
+ explicitly initialized elements.
4418
+
4419
+ For each explicitly initialized element:
4420
+
4421
+ - If the element is an anonymous union member and the initializer list
4422
+ is a brace-enclosed *designated-initializer-list*, the element is
4423
+ initialized by the *braced-init-list* `{ `*D*` }`, where *D* is the
4424
+ *designated-initializer-clause* naming a member of the anonymous union
4425
+ member. There shall be only one such *designated-initializer-clause*.
4426
+ \[*Example 1*:
4427
+ ``` cpp
4428
+ struct C {
4429
+ union {
4430
+ int a;
4431
+ const char* p;
4432
+ };
4433
+ int x;
4434
+ } c = { .a = 1, .x = 3 };
4435
+ ```
4436
+
4437
+ initializes `c.a` with 1 and `c.x` with 3.
4438
+ — *end example*]
4439
+ - Otherwise, if the initializer list is a brace-enclosed
4440
+ *designated-initializer-list*, the element is initialized with the
4441
+ *brace-or-equal-initializer* of the corresponding
4442
+ *designated-initializer-clause*. If that initializer is of the form
4443
+ `= `*assignment-expression* and a narrowing conversion
4444
+ [[dcl.init.list]] is required to convert the expression, the program
4445
+ is ill-formed. \[*Note 2*: The form of the initializer determines
4446
+ whether copy-initialization or direct-initialization is
4447
+ performed. — *end note*]
4448
+ - Otherwise, the initializer list is a brace-enclosed
4449
+ *initializer-list*. If an *initializer-clause* appertains to the
4450
+ aggregate element, then the aggregate element is copy-initialized from
4451
+ the *initializer-clause*. Otherwise, the aggregate element is
4452
+ copy-initialized from a brace-enclosed *initializer-list* consisting
4453
+ of all of the *initializer-clause*s that appertain to subobjects of
4454
+ the aggregate element, in the order of appearance.
4455
+ \[*Note 3*: If an initializer is itself an initializer list, the
4456
+ element is list-initialized, which will result in a recursive
4457
+ application of the rules in this subclause if the element is an
4458
+ aggregate. — *end note*]
4459
+ \[*Example 2*:
4460
+ ``` cpp
4461
+ struct A {
4462
+ int x;
4463
+ struct B {
4464
+ int i;
4465
+ int j;
4466
+ } b;
4467
+ } a = { 1, { 2, 3 } };
4468
+ ```
4469
+
4470
+ initializes `a.x` with 1, `a.b.i` with 2, `a.b.j` with 3.
4471
+ ``` cpp
4472
+ struct base1 { int b1, b2 = 42; };
4473
+ struct base2 {
4474
+ base2() {
4475
+ b3 = 42;
4476
+ }
4477
+ int b3;
4478
+ };
4479
+ struct derived : base1, base2 {
4480
+ int d;
4481
+ };
4482
+
4483
+ derived d1{{1, 2}, {}, 4};
4484
+ derived d2{{}, {}, 4};
4485
+ ```
4486
+
4487
+ initializes `d1.b1` with 1, `d1.b2` with 2, `d1.b3` with 42, `d1.d`
4488
+ with 4, and `d2.b1` with 0, `d2.b2` with 42, `d2.b3` with 42, `d2.d`
4489
+ with 4.
4490
+ — *end example*]
4491
+
4492
+ For a non-union aggregate, each element that is not an explicitly
4493
+ initialized element is initialized as follows:
4494
+
4495
+ - If the element has a default member initializer [[class.mem]], the
4496
+ element is initialized from that initializer.
4497
+ - Otherwise, if the element is not a reference, the element is
4498
+ copy-initialized from an empty initializer list [[dcl.init.list]].
4499
+ - Otherwise, the program is ill-formed.
4500
+
4501
+ If the aggregate is a union and the initializer list is empty, then
4502
+
4503
+ - if any variant member has a default member initializer, that member is
4504
+ initialized from its default member initializer;
4505
+ - otherwise, the first member of the union (if any) is copy-initialized
4506
+ from an empty initializer list.
4507
+
4508
+ [*Example 3*:
4509
+
4510
+ ``` cpp
4511
+ struct S { int a; const char* b; int c; int d = b[a]; };
4512
+ S ss = { 1, "asdf" };
4513
+ ```
4514
+
4515
+ initializes `ss.a` with 1, `ss.b` with `"asdf"`, `ss.c` with the value
4516
+ of an expression of the form `int{}` (that is, `0`), and `ss.d` with the
4517
+ value of `ss.b[ss.a]` (that is, `'s'`).
4518
+
4519
+ ``` cpp
4520
+ struct A {
4521
+ string a;
4522
+ int b = 42;
4523
+ int c = -1;
4524
+ };
4525
+ ```
4526
+
4527
+ `A{.c=21}` has the following steps:
4528
+
4529
+ - Initialize `a` with `{}`
4530
+ - Initialize `b` with `= 42`
4531
+ - Initialize `c` with `= 21`
4532
+
4533
+ — *end example*]
4534
+
4535
+ The initializations of the elements of the aggregate are evaluated in
4536
+ the element order. That is, all value computations and side effects
4537
+ associated with a given element are sequenced before those of any
4538
+ element that follows it in order.
4539
+
4540
+ An aggregate that is a class can also be initialized with a single
4541
+ expression not enclosed in braces, as described in  [[dcl.init]].
4542
+
4543
+ The destructor for each element of class type other than an anonymous
4544
+ union member is potentially invoked [[class.dtor]] from the context
4545
+ where the aggregate initialization occurs.
4546
+
4547
+ [*Note 4*: This provision ensures that destructors can be called for
4548
+ fully-constructed subobjects in case an exception is thrown
4549
+ [[except.ctor]]. — *end note*]
4550
+
4551
+ The number of elements [[dcl.array]] in an array of unknown bound
4552
+ initialized with a brace-enclosed *initializer-list* is the number of
4553
+ explicitly initialized elements of the array.
4554
+
4555
+ [*Example 4*:
4556
+
4557
+ ``` cpp
4558
+ int x[] = { 1, 3, 5 };
4559
+ ```
4560
+
4561
+ declares and initializes `x` as a one-dimensional array that has three
4562
+ elements since no size was specified and there are three initializers.
4563
+
4564
+ — *end example*]
4565
+
4566
+ [*Example 5*:
4567
+
4568
+ In
4569
+
4570
+ ``` cpp
4571
+ struct X { int i, j, k; };
4572
+ X a[] = { 1, 2, 3, 4, 5, 6 };
4573
+ X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
4574
+ ```
4575
+
4576
+ `a` and `b` have the same value.
4577
+
4578
+ — *end example*]
4579
+
4580
+ An array of unknown bound shall not be initialized with an empty
4581
+ *braced-init-list* `{}`.[^6]
4582
+
4583
+ [*Note 5*:
4584
+
4585
+ A default member initializer does not determine the bound for a member
4586
+ array of unknown bound. Since the default member initializer is ignored
4587
+ if a suitable *mem-initializer* is present [[class.base.init]], the
4588
+ default member initializer is not considered to initialize the array of
4589
+ unknown bound.
4590
+
4591
+ [*Example 6*:
4592
+
4593
+ ``` cpp
4594
+ struct S {
4595
+ int y[] = { 0 }; // error: non-static data member of incomplete type
4596
+ };
4597
+ ```
4598
+
4599
+ — *end example*]
4600
+
4601
+ — *end note*]
4602
+
4603
+ [*Note 6*:
4604
+
4605
+ Static data members, non-static data members of anonymous union members,
4606
+ and unnamed bit-fields are not considered elements of the aggregate.
4607
+
4608
+ [*Example 7*:
4609
+
4610
+ ``` cpp
4611
+ struct A {
4612
+ int i;
4613
+ static int s;
4614
+ int j;
4615
+ int :17;
4616
+ int k;
4617
+ } a = { 1, 2, 3 };
4618
+ ```
4619
+
4620
+ Here, the second initializer 2 initializes `a.j` and not the static data
4621
+ member `A::s`, and the third initializer 3 initializes `a.k` and not the
4622
+ unnamed bit-field before it.
4623
+
4624
+ — *end example*]
4625
+
4626
+ — *end note*]
4627
+
4628
+ If a member has a default member initializer and a potentially-evaluated
4629
+ subexpression thereof is an aggregate initialization that would use that
4630
+ default member initializer, the program is ill-formed.
4631
+
4632
+ [*Example 8*:
4633
+
4634
+ ``` cpp
4635
+ struct A;
4636
+ extern A a;
4637
+ struct A {
4638
+ const A& a1 { A{a,a} }; // OK
4639
+ const A& a2 { A{} }; // error
4640
+ };
4641
+ A a{a,a}; // OK
4642
+
4643
+ struct B {
4644
+ int n = B{}.n; // error
4645
+ };
4646
+ ```
4647
+
4648
+ — *end example*]
4649
+
4650
+ When initializing a multidimensional array, the *initializer-clause*s
4651
+ initialize the elements with the last (rightmost) index of the array
4652
+ varying the fastest [[dcl.array]].
4653
+
4654
+ [*Example 9*:
4655
+
4656
+ ``` cpp
4657
+ int x[2][2] = { 3, 1, 4, 2 };
4658
+ ```
4659
+
4660
+ initializes `x[0][0]` to `3`, `x[0][1]` to `1`, `x[1][0]` to `4`, and
4661
+ `x[1][1]` to `2`. On the other hand,
4662
+
4663
+ ``` cpp
4664
+ float y[4][3] = {
4665
+ { 1 }, { 2 }, { 3 }, { 4 }
4666
+ };
4667
+ ```
4668
+
4669
+ initializes the first column of `y` (regarded as a two-dimensional
4670
+ array) and leaves the rest zero.
4671
+
4672
+ — *end example*]
4673
+
4674
+ Each *initializer-clause* in a brace-enclosed *initializer-list* is said
4675
+ to *appertain* to an element of the aggregate being initialized or to an
4676
+ element of one of its subaggregates. Considering the sequence of
4677
+ *initializer-clause*s, and the sequence of aggregate elements initially
4678
+ formed as the sequence of elements of the aggregate being initialized
4679
+ and potentially modified as described below, each *initializer-clause*
4680
+ appertains to the corresponding aggregate element if
4681
+
4682
+ - the aggregate element is not an aggregate, or
4683
+ - the *initializer-clause* begins with a left brace, or
4684
+ - the *initializer-clause* is an expression and an implicit conversion
4685
+ sequence can be formed that converts the expression to the type of the
4686
+ aggregate element, or
4687
+ - the aggregate element is an aggregate that itself has no aggregate
4688
+ elements.
4689
+
4690
+ Otherwise, the aggregate element is an aggregate and that subaggregate
4691
+ is replaced in the list of aggregate elements by the sequence of its own
4692
+ aggregate elements, and the appertainment analysis resumes with the
4693
+ first such element and the same *initializer-clause*.
4694
+
4695
+ [*Note 7*:
4696
+
4697
+ These rules apply recursively to the aggregate’s subaggregates.
4698
+
4699
+ [*Example 10*:
4700
+
4701
+ In
4702
+
4703
+ ``` cpp
4704
+ struct S1 { int a, b; };
4705
+ struct S2 { S1 s, t; };
4706
+
4707
+ S2 x[2] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4708
+ S2 y[2] = {
4709
+ {
4710
+ { 1, 2 },
4711
+ { 3, 4 }
4712
+ },
4713
+ {
4714
+ { 5, 6 },
4715
+ { 7, 8 }
4716
+ }
4717
+ };
4718
+ ```
4719
+
4720
+ `x` and `y` have the same value.
4721
+
4722
+ — *end example*]
4723
+
4724
+ — *end note*]
4725
+
4726
+ This process continues until all *initializer-clause*s have been
4727
+ exhausted. If any *initializer-clause* remains that does not appertain
4728
+ to an element of the aggregate or one of its subaggregates, the program
4729
+ is ill-formed.
4730
+
4731
+ [*Example 11*:
4732
+
4733
+ ``` cpp
4734
+ char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error: too many initializers
4735
+ ```
4736
+
4737
+ — *end example*]
4738
+
4739
+ [*Example 12*:
4740
+
4741
+ ``` cpp
4742
+ float y[4][3] = {
4743
+ { 1, 3, 5 },
4744
+ { 2, 4, 6 },
4745
+ { 3, 5, 7 },
4746
+ };
4747
+ ```
4748
+
4749
+ is a completely-braced initialization: 1, 3, and 5 initialize the first
4750
+ row of the array `y[0]`, namely `y[0][0]`, `y[0][1]`, and `y[0][2]`.
4751
+ Likewise the next two lines initialize `y[1]` and `y[2]`. The
4752
+ initializer ends early and therefore `y[3]`’s elements are initialized
4753
+ as if explicitly initialized with an expression of the form `float()`,
4754
+ that is, are initialized with `0.0`. In the following example, braces in
4755
+ the *initializer-list* are elided; however the *initializer-list* has
4756
+ the same effect as the completely-braced *initializer-list* of the above
4757
+ example,
4758
+
4759
+ ``` cpp
4760
+ float y[4][3] = {
4761
+ 1, 3, 5, 2, 4, 6, 3, 5, 7
4762
+ };
4763
+ ```
4764
+
4765
+ The initializer for `y` begins with a left brace, but the one for `y[0]`
4766
+ does not, therefore three elements from the list are used. Likewise the
4767
+ next three are taken successively for `y[1]` and `y[2]`.
4768
+
4769
+ — *end example*]
4770
+
4771
+ [*Note 8*:
4772
+
4773
+ The initializer for an empty subaggregate is needed if any initializers
4774
+ are provided for subsequent elements.
4775
+
4776
+ [*Example 13*:
4777
+
4778
+ ``` cpp
4779
+ struct S { } s;
4780
+ struct A {
4781
+ S s1;
4782
+ int i1;
4783
+ S s2;
4784
+ int i2;
4785
+ S s3;
4786
+ int i3;
4787
+ } a = {
4788
+ { }, // Required initialization
4789
+ 0,
4790
+ s, // Required initialization
4791
+ 0
4792
+ }; // Initialization not required for A::s3 because A::i3 is also not initialized
4793
+ ```
4794
+
4795
+ — *end example*]
4796
+
4797
+ — *end note*]
4798
+
4799
+ [*Example 14*:
4800
+
4801
+ ``` cpp
4802
+ struct A {
4803
+ int i;
4804
+ operator int();
4805
+ };
4806
+ struct B {
4807
+ A a1, a2;
4808
+ int z;
4809
+ };
4810
+ A a;
4811
+ B b = { 4, a, a };
4812
+ ```
4813
+
4814
+ Braces are elided around the *initializer-clause* for `b.a1.i`. `b.a1.i`
4815
+ is initialized with 4, `b.a2` is initialized with `a`, `b.z` is
4816
+ initialized with whatever `a.operator int()` returns.
4817
+
4818
+ — *end example*]
4819
+
4820
+ [*Note 9*: An aggregate array or an aggregate class can contain
4821
+ elements of a class type with a user-declared constructor
4822
+ [[class.ctor]]. Initialization of these aggregate objects is described
4823
+ in  [[class.expl.init]]. — *end note*]
4824
+
4825
+ [*Note 10*: Whether the initialization of aggregates with static
4826
+ storage duration is static or dynamic is specified in 
4827
+ [[basic.start.static]], [[basic.start.dynamic]], and 
4828
+ [[stmt.dcl]]. — *end note*]
4829
+
4830
+ When a union is initialized with an initializer list, there shall not be
4831
+ more than one explicitly initialized element.
4832
+
4833
+ [*Example 15*:
4834
+
4835
+ ``` cpp
4836
+ union u { int a; const char* b; };
4837
+ u a = { 1 };
4838
+ u b = a;
4839
+ u c = 1; // error
4840
+ u d = { 0, "asdf" }; // error
4841
+ u e = { "asdf" }; // error
4842
+ u f = { .b = "asdf" };
4843
+ u g = { .a = 1, .b = "asdf" }; // error
4844
+ ```
4845
+
4846
+ — *end example*]
4847
+
4848
+ [*Note 11*: As described above, the braces around the
4849
+ *initializer-clause* for a union member can be omitted if the union is a
4850
+ member of another aggregate. — *end note*]
4851
+
4852
+ ### Character arrays <a id="dcl.init.string">[[dcl.init.string]]</a>
4853
+
4854
+ An array of ordinary character type [[basic.fundamental]], `char8_t`
4855
+ array, `char16_t` array, `char32_t` array, or `wchar_t` array may be
4856
+ initialized by an ordinary string literal, UTF-8 string literal, UTF-16
4857
+ string literal, UTF-32 string literal, or wide string literal,
4858
+ respectively, or by an appropriately-typed *string-literal* enclosed in
4859
+ braces [[lex.string]]. Additionally, an array of `char` or
4860
+ `unsigned char` may be initialized by a UTF-8 string literal, or by such
4861
+ a string literal enclosed in braces. Successive characters of the value
4862
+ of the *string-literal* initialize the elements of the array, with an
4863
+ integral conversion [[conv.integral]] if necessary for the source and
4864
+ destination value.
4865
+
4866
+ [*Example 1*:
4867
+
4868
+ ``` cpp
4869
+ char msg[] = "Syntax error on line %s\n";
4870
+ ```
4871
+
4872
+ shows a character array whose members are initialized with a
4873
+ *string-literal*. Note that because `'\n'` is a single character and
4874
+ because a trailing `'\0'` is appended, `sizeof(msg)` is `25`.
4875
+
4876
+ — *end example*]
4877
+
4878
+ There shall not be more initializers than there are array elements.
4879
+
4880
+ [*Example 2*:
4881
+
4882
+ ``` cpp
4883
+ char cv[4] = "asdf"; // error
4884
+ ```
4885
+
4886
+ is ill-formed since there is no space for the implied trailing `'\0'`.
4887
+
4888
+ — *end example*]
4889
+
4890
+ If there are fewer initializers than there are array elements, each
4891
+ element not explicitly initialized shall be zero-initialized
4892
+ [[dcl.init]].
4893
+
4894
+ ### References <a id="dcl.init.ref">[[dcl.init.ref]]</a>
4895
+
4896
+ A variable whose declared type is “reference to `T`” [[dcl.ref]] shall
4897
+ be initialized.
4898
+
4899
+ [*Example 1*:
4900
+
4901
+ ``` cpp
4902
+ int g(int) noexcept;
4903
+ void f() {
4904
+ int i;
4905
+ int& r = i; // r refers to i
4906
+ r = 1; // the value of i becomes 1
4907
+ int* p = &r; // p points to i
4908
+ int& rr = r; // rr refers to what r refers to, that is, to i
4909
+ int (&rg)(int) = g; // rg refers to the function g
4910
+ rg(i); // calls function g
4911
+ int a[3];
4912
+ int (&ra)[3] = a; // ra refers to the array a
4913
+ ra[1] = i; // modifies a[1]
4914
+ }
4915
+ ```
4916
+
4917
+ — *end example*]
4918
+
4919
+ A reference cannot be changed to refer to another object after
4920
+ initialization.
4921
+
4922
+ [*Note 1*: Assignment to a reference assigns to the object referred to
4923
+ by the reference [[expr.assign]]. — *end note*]
4924
+
4925
+ Argument passing [[expr.call]] and function value return [[stmt.return]]
4926
+ are initializations.
4927
+
4928
+ The initializer can be omitted for a reference only in a parameter
4929
+ declaration [[dcl.fct]], in the declaration of a function return type,
4930
+ in the declaration of a class member within its class definition
4931
+ [[class.mem]], and where the `extern` specifier is explicitly used.
4932
+
4933
+ [*Example 2*:
4934
+
4935
+ ``` cpp
4936
+ int& r1; // error: initializer missing
4937
+ extern int& r2; // OK
4938
+ ```
4939
+
4940
+ — *end example*]
4941
+
4942
+ Given types “*cv1* `T1`” and “*cv2* `T2`”, “*cv1* `T1`” is
4943
+ *reference-related* to “*cv2* `T2`” if `T1` is similar [[conv.qual]] to
4944
+ `T2`, or `T1` is a base class of `T2`. “*cv1* `T1`” is
4945
+ *reference-compatible* with “*cv2* `T2`” if a prvalue of type “pointer
4946
+ to *cv2* `T2`” can be converted to the type “pointer to *cv1* `T1`” via
4947
+ a standard conversion sequence [[conv]]. In all cases where the
4948
+ reference-compatible relationship of two types is used to establish the
4949
+ validity of a reference binding and the standard conversion sequence
4950
+ would be ill-formed, a program that necessitates such a binding is
4951
+ ill-formed.
4952
+
4953
+ A reference to type “*cv1* `T1`” is initialized by an expression of type
4954
+ “*cv2* `T2`” as follows:
4955
+
4956
+ - If the reference is an lvalue reference and the initializer expression
4957
+ - is an lvalue (but is not a bit-field), and “*cv1* `T1`” is
4958
+ reference-compatible with “*cv2* `T2`”, or
4959
+ - has a class type (i.e., `T2` is a class type), where `T1` is not
4960
+ reference-related to `T2`, and can be converted to an lvalue of type
4961
+ “*cv3* `T3`”, where “*cv1* `T1`” is reference-compatible with “*cv3*
4962
+ `T3`”[^7] (this conversion is selected by enumerating the applicable
4963
+ conversion functions [[over.match.ref]] and choosing the best one
4964
+ through overload resolution [[over.match]]),
4965
+
4966
+ then the reference binds to the initializer expression lvalue in the
4967
+ first case and to the lvalue result of the conversion in the second
4968
+ case (or, in either case, to the appropriate base class subobject of
4969
+ the object).
4970
+ \[*Note 2*: The usual lvalue-to-rvalue [[conv.lval]], array-to-pointer
4971
+ [[conv.array]], and function-to-pointer [[conv.func]] standard
4972
+ conversions are not needed, and therefore are suppressed, when such
4973
+ direct bindings to lvalues are done. — *end note*]
4974
+ \[*Example 3*:
4975
+ ``` cpp
4976
+ double d = 2.0;
4977
+ double& rd = d; // rd refers to d
4978
+ const double& rcd = d; // rcd refers to d
4979
+
4980
+ struct A { };
4981
+ struct B : A { operator int&(); } b;
4982
+ A& ra = b; // ra refers to A subobject in b
4983
+ const A& rca = b; // rca refers to A subobject in b
4984
+ int& ir = B(); // ir refers to the result of B::operator int&
4985
+ ```
4986
+
4987
+ — *end example*]
4988
+ - Otherwise, if the reference is an lvalue reference to a type that is
4989
+ not const-qualified or is volatile-qualified, the program is
4990
+ ill-formed.
4991
+ \[*Example 4*:
4992
+ ``` cpp
4993
+ double& rd2 = 2.0; // error: not an lvalue and reference not const
4994
+ int i = 2;
4995
+ double& rd3 = i; // error: type mismatch and reference not const
4996
+ ```
4997
+
4998
+ — *end example*]
4999
+ - Otherwise, if the initializer expression
5000
+ - is an rvalue (but not a bit-field) or an lvalue of function type and
5001
+ “*cv1* `T1`” is reference-compatible with “*cv2* `T2`”, or
5002
+ - has a class type (i.e., `T2` is a class type), where `T1` is not
5003
+ reference-related to `T2`, and can be converted to an rvalue of type
5004
+ “*cv3* `T3`” or an lvalue of function type “*cv3* `T3`”, where
5005
+ “*cv1* `T1`” is reference-compatible with “*cv3* `T3`” (see 
5006
+ [[over.match.ref]]),
5007
+
5008
+ then the initializer expression in the first case and the converted
5009
+ expression in the second case is called the converted initializer. If
5010
+ the converted initializer is a prvalue, let its type be denoted by
5011
+ `T4`; the temporary materialization conversion [[conv.rval]] is
5012
+ applied, considering the type of the prvalue to be “*cv1* `T4`”
5013
+ [[conv.qual]]. In any case, the reference binds to the resulting
5014
+ glvalue (or to an appropriate base class subobject).
5015
+ \[*Example 5*:
5016
+ ``` cpp
5017
+ struct A { };
5018
+ struct B : A { } b;
5019
+ extern B f();
5020
+ const A& rca2 = f(); // binds to the A subobject of the B rvalue.
5021
+ A&& rra = f(); // same as above
5022
+ struct X {
5023
+ operator B();
5024
+ operator int&();
5025
+ } x;
5026
+ const A& r = x; // binds to the A subobject of the result of the conversion
5027
+ int i2 = 42;
5028
+ int&& rri = static_cast<int&&>(i2); // binds directly to i2
5029
+ B&& rrb = x; // binds directly to the result of operator B
5030
+
5031
+ constexpr int f() {
5032
+ const int &x = 42;
5033
+ const_cast<int &>(x) = 1; // undefined behavior
5034
+ return x;
5035
+ }
5036
+ constexpr int z = f(); // error: not a constant expression
5037
+
5038
+ typedef int *AP[3]; // array of 3 pointer to int
5039
+ typedef const int *const ACPC[3]; // array of 3 const pointer to const int
5040
+ ACPC &&r = AP{}; // binds directly
5041
+ ```
5042
+
5043
+ — *end example*]
5044
+ - Otherwise, `T1` shall not be reference-related to `T2`.
5045
+ - If `T1` or `T2` is a class type, user-defined conversions are
5046
+ considered using the rules for copy-initialization of an object of
5047
+ type “*cv1* `T1`” by user-defined conversion
5048
+ [[dcl.init]], [[over.match.copy]], [[over.match.conv]]; the program
5049
+ is ill-formed if the corresponding non-reference copy-initialization
5050
+ would be ill-formed. The result E of the call to the conversion
5051
+ function, as described for the non-reference copy-initialization, is
5052
+ then used to direct-initialize the reference using the form `(E)`.
5053
+ For this direct-initialization, user-defined conversions are not
5054
+ considered.
5055
+ - Otherwise, the initializer expression is implicitly converted to a
5056
+ prvalue of type “`T1`”. The temporary materialization conversion is
5057
+ applied, considering the type of the prvalue to be “*cv1* `T1`”, and
5058
+ the reference is bound to the result.
5059
+
5060
+ \[*Example 6*:
5061
+ ``` cpp
5062
+ struct Banana { };
5063
+ struct Enigma { operator const Banana(); };
5064
+ struct Alaska { operator Banana&(); };
5065
+ void enigmatic() {
5066
+ typedef const Banana ConstBanana;
5067
+ Banana &&banana1 = ConstBanana(); // error
5068
+ Banana &&banana2 = Enigma(); // error
5069
+ Banana &&banana3 = Alaska(); // error
5070
+ }
5071
+
5072
+ const double& rcd2 = 2; // rcd2 refers to temporary with type const double and value 2.0
5073
+ double&& rrd = 2; // rrd refers to temporary with value 2.0
5074
+ const volatile int cvi = 1;
5075
+ const int& r2 = cvi; // error: cv-qualifier dropped
5076
+ struct A { operator volatile int&(); } a;
5077
+ const int& r3 = a; // error: cv-qualifier dropped
5078
+ // from result of conversion function
5079
+ double d2 = 1.0;
5080
+ double&& rrd2 = d2; // error: initializer is lvalue of reference-related type
5081
+ struct X { operator int&(); };
5082
+ int&& rri2 = X(); // error: result of conversion function is
5083
+ // lvalue of reference-related type
5084
+ int i3 = 2;
5085
+ double&& rrd3 = i3; // rrd3 refers to temporary with value 2.0
5086
+ ```
5087
+
5088
+ — *end example*]
5089
+
5090
+ In all cases except the last (i.e., implicitly converting the
5091
+ initializer expression to the referenced type), the reference is said to
5092
+ *bind directly* to the initializer expression.
5093
+
5094
+ [*Note 3*: [[class.temporary]] describes the lifetime of temporaries
5095
+ bound to references. — *end note*]
5096
+
5097
+ ### List-initialization <a id="dcl.init.list">[[dcl.init.list]]</a>
5098
+
5099
+ *List-initialization* is initialization of an object or reference from a
5100
+ *braced-init-list*. Such an initializer is called an *initializer list*,
5101
+ and the comma-separated *initializer-clause*s of the *initializer-list*
5102
+ or *designated-initializer-clause*s of the *designated-initializer-list*
5103
+ are called the *elements* of the initializer list. An initializer list
5104
+ may be empty. List-initialization can occur in direct-initialization or
5105
+ copy-initialization contexts; list-initialization in a
5106
+ direct-initialization context is called *direct-list-initialization* and
5107
+ list-initialization in a copy-initialization context is called
5108
+ *copy-list-initialization*. Direct-initialization that is not
5109
+ list-initialization is called *direct-non-list-initialization*.
5110
+
5111
+ [*Note 1*:
5112
+
5113
+ List-initialization can be used
5114
+
5115
+ - as the initializer in a variable definition [[dcl.init]],
5116
+ - as the initializer in a *new-expression* [[expr.new]],
5117
+ - in a `return` statement [[stmt.return]],
5118
+ - as a *for-range-initializer* [[stmt.iter]],
5119
+ - as a function argument [[expr.call]],
5120
+ - as a template argument [[temp.arg.nontype]],
5121
+ - as a subscript [[expr.sub]],
5122
+ - as an argument to a constructor invocation
5123
+ [[dcl.init]], [[expr.type.conv]],
5124
+ - as an initializer for a non-static data member [[class.mem]],
5125
+ - in a *mem-initializer* [[class.base.init]], or
5126
+ - on the right-hand side of an assignment [[expr.assign]].
5127
+
5128
+ [*Example 1*:
5129
+
5130
+ ``` cpp
5131
+ int a = {1};
5132
+ std::complex<double> z{1,2};
5133
+ new std::vector<std::string>{"once", "upon", "a", "time"}; // 4 string elements
5134
+ f( {"Nicholas","Annemarie"} ); // pass list of two elements
5135
+ return { "Norah" }; // return list of one element
5136
+ int* e {}; // initialization to zero / null pointer
5137
+ x = double{1}; // explicitly construct a double
5138
+ std::map<std::string,int> anim = { {"bear",4}, {"cassowary",2}, {"tiger",7} };
5139
+ ```
5140
+
5141
+ — *end example*]
5142
+
5143
+ — *end note*]
5144
+
5145
+ A constructor is an *initializer-list constructor* if its first
5146
+ parameter is of type `std::initializer_list<E>` or reference to
5147
+ cv `std::initializer_list<E>` for some type `E`, and either there are no
5148
+ other parameters or else all other parameters have default arguments
5149
+ [[dcl.fct.default]].
5150
+
5151
+ [*Note 2*: Initializer-list constructors are favored over other
5152
+ constructors in list-initialization [[over.match.list]]. Passing an
5153
+ initializer list as the argument to the constructor template
5154
+ `template<class T> C(T)` of a class `C` does not create an
5155
+ initializer-list constructor, because an initializer list argument
5156
+ causes the corresponding parameter to be a non-deduced context
5157
+ [[temp.deduct.call]]. — *end note*]
5158
+
5159
+ The template `std::initializer_list` is not predefined; if a standard
5160
+ library declaration [[initializer.list.syn]], [[std.modules]] of
5161
+ `std::initializer_list` is not reachable from [[module.reach]] a use of
5162
+ `std::initializer_list` — even an implicit use in which the type is not
5163
+ named [[dcl.spec.auto]] — the program is ill-formed.
5164
+
5165
+ List-initialization of an object or reference of type *cv* `T` is
5166
+ defined as follows:
5167
+
5168
+ - If the *braced-init-list* contains a *designated-initializer-list* and
5169
+ `T` is not a reference type, `T` shall be an aggregate class. The
5170
+ ordered *identifier*s in the *designator*s of the
5171
+ *designated-initializer-list* shall form a subsequence of the ordered
5172
+ *identifier*s in the direct non-static data members of `T`. Aggregate
5173
+ initialization is performed [[dcl.init.aggr]].
5174
+ \[*Example 2*:
5175
+ ``` cpp
5176
+ struct A { int x; int y; int z; };
5177
+ A a{.y = 2, .x = 1}; // error: designator order does not match declaration order
5178
+ A b{.x = 1, .z = 2}; // OK, b.y initialized to 0
5179
+ ```
5180
+
5181
+ — *end example*]
5182
+ - If `T` is an aggregate class and the initializer list has a single
5183
+ element of type *cv1* `U`, where `U` is `T` or a class derived from
5184
+ `T`, the object is initialized from that element (by
5185
+ copy-initialization for copy-list-initialization, or by
5186
+ direct-initialization for direct-list-initialization).
5187
+ - Otherwise, if `T` is a character array and the initializer list has a
5188
+ single element that is an appropriately-typed *string-literal*
5189
+ [[dcl.init.string]], initialization is performed as described in that
5190
+ subclause.
5191
+ - Otherwise, if `T` is an aggregate, aggregate initialization is
5192
+ performed [[dcl.init.aggr]].
5193
+ \[*Example 3*:
5194
+ ``` cpp
5195
+ double ad[] = { 1, 2.0 }; // OK
5196
+ int ai[] = { 1, 2.0 }; // error: narrowing
5197
+
5198
+ struct S2 {
5199
+ int m1;
5200
+ double m2, m3;
5201
+ };
5202
+ S2 s21 = { 1, 2, 3.0 }; // OK
5203
+ S2 s22 { 1.0, 2, 3 }; // error: narrowing
5204
+ S2 s23 { }; // OK, default to 0,0,0
5205
+ ```
5206
+
5207
+ — *end example*]
5208
+ - Otherwise, if the initializer list has no elements and `T` is a class
5209
+ type with a default constructor, the object is value-initialized.
5210
+ - Otherwise, if `T` is a specialization of `std::initializer_list`, the
5211
+ object is constructed as described below.
5212
+ - Otherwise, if `T` is a class type, constructors are considered. The
5213
+ applicable constructors are enumerated and the best one is chosen
5214
+ through overload resolution [[over.match]], [[over.match.list]]. If a
5215
+ narrowing conversion (see below) is required to convert any of the
5216
+ arguments, the program is ill-formed.
5217
+ \[*Example 4*:
5218
+ ``` cpp
5219
+ struct S {
5220
+ S(std::initializer_list<double>); // #1
5221
+ S(std::initializer_list<int>); // #2
5222
+ S(std::initializer_list<S>); // #3
5223
+ S(); // #4
5224
+ // ...
5225
+ };
5226
+ S s1 = { 1.0, 2.0, 3.0 }; // invoke #1
5227
+ S s2 = { 1, 2, 3 }; // invoke #2
5228
+ S s3{s2}; // invoke #3 (not the copy constructor)
5229
+ S s4 = { }; // invoke #4
5230
+ ```
5231
+
5232
+ — *end example*]
5233
+ \[*Example 5*:
5234
+ ``` cpp
5235
+ struct Map {
5236
+ Map(std::initializer_list<std::pair<std::string,int>>);
5237
+ };
5238
+ Map ship = {{"Sophie",14}, {"Surprise",28}};
5239
+ ```
5240
+
5241
+ — *end example*]
5242
+ \[*Example 6*:
5243
+ ``` cpp
5244
+ struct S {
5245
+ // no initializer-list constructors
5246
+ S(int, double, double); // #1
5247
+ S(); // #2
5248
+ // ...
5249
+ };
5250
+ S s1 = { 1, 2, 3.0 }; // OK, invoke #1
5251
+ S s2 { 1.0, 2, 3 }; // error: narrowing
5252
+ S s3 { }; // OK, invoke #2
5253
+ ```
5254
+
5255
+ — *end example*]
5256
+ - Otherwise, if `T` is an enumeration with a fixed underlying type
5257
+ [[dcl.enum]] `U`, the *initializer-list* has a single element `v` of
5258
+ scalar type, `v` can be implicitly converted to `U`, and the
5259
+ initialization is direct-list-initialization, the object is
5260
+ initialized with the value `T(v)` [[expr.type.conv]]; if a narrowing
5261
+ conversion is required to convert `v` to `U`, the program is
5262
+ ill-formed.
5263
+ \[*Example 7*:
5264
+ ``` cpp
5265
+ enum byte : unsigned char { };
5266
+ byte b { 42 }; // OK
5267
+ byte c = { 42 }; // error
5268
+ byte d = byte{ 42 }; // OK; same value as b
5269
+ byte e { -1 }; // error
5270
+
5271
+ struct A { byte b; };
5272
+ A a1 = { { 42 } }; // error
5273
+ A a2 = { byte{ 42 } }; // OK
5274
+
5275
+ void f(byte);
5276
+ f({ 42 }); // error
5277
+
5278
+ enum class Handle : uint32_t { Invalid = 0 };
5279
+ Handle h { 42 }; // OK
5280
+ ```
5281
+
5282
+ — *end example*]
5283
+ - Otherwise, if the initializer list is not a
5284
+ *designated-initializer-list* and has a single element of type `E` and
5285
+ either `T` is not a reference type or its referenced type is
5286
+ reference-related to `E`, the object or reference is initialized from
5287
+ that element (by copy-initialization for copy-list-initialization, or
5288
+ by direct-initialization for direct-list-initialization); if a
5289
+ narrowing conversion (see below) is required to convert the element to
5290
+ `T`, the program is ill-formed.
5291
+ \[*Example 8*:
5292
+ ``` cpp
5293
+ int x1 {2}; // OK
5294
+ int x2 {2.0}; // error: narrowing
5295
+ ```
5296
+
5297
+ — *end example*]
5298
+ - Otherwise, if `T` is a reference type, a prvalue is generated. The
5299
+ prvalue initializes its result object by copy-list-initialization from
5300
+ the initializer list. The prvalue is then used to direct-initialize
5301
+ the reference. The type of the prvalue is the type referenced by `T`,
5302
+ unless `T` is “reference to array of unknown bound of `U`”, in which
5303
+ case the type of the prvalue is the type of `x` in the declaration
5304
+ `U x[] H`, where H is the initializer list.
5305
+ \[*Note 3*: As usual, the binding will fail and the program is
5306
+ ill-formed if the reference type is an lvalue reference to a non-const
5307
+ type. — *end note*]
5308
+ \[*Example 9*:
5309
+ ``` cpp
5310
+ struct S {
5311
+ S(std::initializer_list<double>); // #1
5312
+ S(const std::string&); // #2
5313
+ // ...
5314
+ };
5315
+ const S& r1 = { 1, 2, 3.0 }; // OK, invoke #1
5316
+ const S& r2 { "Spinach" }; // OK, invoke #2
5317
+ S& r3 = { 1, 2, 3 }; // error: initializer is not an lvalue
5318
+ const int& i1 = { 1 }; // OK
5319
+ const int& i2 = { 1.1 }; // error: narrowing
5320
+ const int (&iar)[2] = { 1, 2 }; // OK, iar is bound to temporary array
5321
+
5322
+ struct A { } a;
5323
+ struct B { explicit B(const A&); };
5324
+ const B& b2{a}; // error: cannot copy-list-initialize B temporary from A
5325
+
5326
+ struct C { int x; };
5327
+ C&& c = { .x = 1 }; // OK
5328
+ ```
5329
+
5330
+ — *end example*]
5331
+ - Otherwise, if the initializer list has no elements, the object is
5332
+ value-initialized.
5333
+ \[*Example 10*:
5334
+ ``` cpp
5335
+ int** pp {}; // initialized to null pointer
5336
+ ```
5337
+
5338
+ — *end example*]
5339
+ - Otherwise, the program is ill-formed.
5340
+ \[*Example 11*:
5341
+ ``` cpp
5342
+ struct A { int i; int j; };
5343
+ A a1 { 1, 2 }; // aggregate initialization
5344
+ A a2 { 1.2 }; // error: narrowing
5345
+ struct B {
5346
+ B(std::initializer_list<int>);
5347
+ };
5348
+ B b1 { 1, 2 }; // creates initializer_list<int> and calls constructor
5349
+ B b2 { 1, 2.0 }; // error: narrowing
5350
+ struct C {
5351
+ C(int i, double j);
5352
+ };
5353
+ C c1 = { 1, 2.2 }; // calls constructor with arguments (1, 2.2)
5354
+ C c2 = { 1.1, 2 }; // error: narrowing
5355
+
5356
+ int j { 1 }; // initialize to 1
5357
+ int k { }; // initialize to 0
5358
+ ```
5359
+
5360
+ — *end example*]
5361
+
5362
+ Within the *initializer-list* of a *braced-init-list*, the
5363
+ *initializer-clause*s, including any that result from pack expansions
5364
+ [[temp.variadic]], are evaluated in the order in which they appear. That
5365
+ is, every value computation and side effect associated with a given
5366
+ *initializer-clause* is sequenced before every value computation and
5367
+ side effect associated with any *initializer-clause* that follows it in
5368
+ the comma-separated list of the *initializer-list*.
5369
+
5370
+ [*Note 4*: This evaluation ordering holds regardless of the semantics
5371
+ of the initialization; for example, it applies when the elements of the
5372
+ *initializer-list* are interpreted as arguments of a constructor call,
5373
+ even though ordinarily there are no sequencing constraints on the
5374
+ arguments of a call. — *end note*]
5375
+
5376
+ An object of type `std::initializer_list<E>` is constructed from an
5377
+ initializer list as if the implementation generated and materialized
5378
+ [[conv.rval]] a prvalue of type “array of N `const E`”, where N is the
5379
+ number of elements in the initializer list; this is called the
5380
+ initializer list’s *backing array*. Each element of the backing array is
5381
+ copy-initialized with the corresponding element of the initializer list,
5382
+ and the `std::initializer_list<E>` object is constructed to refer to
5383
+ that array.
5384
+
5385
+ [*Note 5*: A constructor or conversion function selected for the copy
5386
+ needs to be accessible [[class.access]] in the context of the
5387
+ initializer list. — *end note*]
5388
+
5389
+ If a narrowing conversion is required to initialize any of the elements,
5390
+ the program is ill-formed.
5391
+
5392
+ [*Note 6*: Backing arrays are potentially non-unique objects
5393
+ [[intro.object]]. — *end note*]
5394
+
5395
+ The backing array has the same lifetime as any other temporary object
5396
+ [[class.temporary]], except that initializing an `initializer_list`
5397
+ object from the array extends the lifetime of the array exactly like
5398
+ binding a reference to a temporary.
5399
+
5400
+ [*Example 12*:
5401
+
5402
+ ``` cpp
5403
+ void f(std::initializer_list<double> il);
5404
+ void g(float x) {
5405
+ f({1, x, 3});
5406
+ }
5407
+ void h() {
5408
+ f({1, 2, 3});
5409
+ }
5410
+
5411
+ struct A {
5412
+ mutable int i;
5413
+ };
5414
+ void q(std::initializer_list<A>);
5415
+ void r() {
5416
+ q({A{1}, A{2}, A{3}});
5417
+ }
5418
+ ```
5419
+
5420
+ The initialization will be implemented in a way roughly equivalent to
5421
+ this:
5422
+
5423
+ ``` cpp
5424
+ void g(float x) {
5425
+ const double __a[3] = {double{1}, double{x}, double{3}}; // backing array
5426
+ f(std::initializer_list<double>(__a, __a+3));
5427
+ }
5428
+ void h() {
5429
+ static constexpr double __b[3] = {double{1}, double{2}, double{3}}; // backing array
5430
+ f(std::initializer_list<double>(__b, __b+3));
5431
+ }
5432
+ void r() {
5433
+ const A __c[3] = {A{1}, A{2}, A{3}}; // backing array
5434
+ q(std::initializer_list<A>(__c, __c+3));
5435
+ }
5436
+ ```
5437
+
5438
+ assuming that the implementation can construct an `initializer_list`
5439
+ object with a pair of pointers, and with the understanding that `__b`
5440
+ does not outlive the call to `f`.
5441
+
5442
+ — *end example*]
5443
+
5444
+ [*Example 13*:
5445
+
5446
+ ``` cpp
5447
+ typedef std::complex<double> cmplx;
5448
+ std::vector<cmplx> v1 = { 1, 2, 3 };
5449
+
5450
+ void f() {
5451
+ std::vector<cmplx> v2{ 1, 2, 3 };
5452
+ std::initializer_list<int> i3 = { 1, 2, 3 };
5453
+ }
5454
+
5455
+ struct A {
5456
+ std::initializer_list<int> i4;
5457
+ A() : i4{ 1, 2, 3 } {} // ill-formed, would create a dangling reference
5458
+ };
5459
+ ```
5460
+
5461
+ For `v1` and `v2`, the `initializer_list` object is a parameter in a
5462
+ function call, so the array created for `{ 1, 2, 3 }` has
5463
+ full-expression lifetime. For `i3`, the `initializer_list` object is a
5464
+ variable, so the array persists for the lifetime of the variable. For
5465
+ `i4`, the `initializer_list` object is initialized in the constructor’s
5466
+ *ctor-initializer* as if by binding a temporary array to a reference
5467
+ member, so the program is ill-formed [[class.base.init]].
5468
+
5469
+ — *end example*]
5470
+
5471
+ A *narrowing conversion* is an implicit conversion
5472
+
5473
+ - from a floating-point type to an integer type, or
5474
+ - from a floating-point type `T` to another floating-point type whose
5475
+ floating-point conversion rank is neither greater than nor equal to
5476
+ that of `T`, except where the result of the conversion is a constant
5477
+ expression and either its value is finite and the conversion did not
5478
+ overflow, or the values before and after the conversion are not
5479
+ finite, or
5480
+ - from an integer type or unscoped enumeration type to a floating-point
5481
+ type, except where the source is a constant expression and the actual
5482
+ value after conversion will fit into the target type and will produce
5483
+ the original value when converted back to the original type, or
5484
+ - from an integer type or unscoped enumeration type to an integer type
5485
+ that cannot represent all the values of the original type, except
5486
+ where
5487
+ - the source is a bit-field whose width w is less than that of its
5488
+ type (or, for an enumeration type, its underlying type) and the
5489
+ target type can represent all the values of a hypothetical extended
5490
+ integer type with width w and with the same signedness as the
5491
+ original type or
5492
+ - the source is a constant expression whose value after integral
5493
+ promotions will fit into the target type, or
5494
+ - from a pointer type or a pointer-to-member type to `bool`.
5495
+
5496
+ [*Note 7*: As indicated above, such conversions are not allowed at the
5497
+ top level in list-initializations. — *end note*]
5498
+
5499
+ [*Example 14*:
5500
+
5501
+ ``` cpp
5502
+ int x = 999; // x is not a constant expression
5503
+ const int y = 999;
5504
+ const int z = 99;
5505
+ char c1 = x; // OK, though it potentially narrows (in this case, it does narrow)
5506
+ char c2{x}; // error: potentially narrows
5507
+ char c3{y}; // error: narrows (assuming char is 8 bits)
5508
+ char c4{z}; // OK, no narrowing needed
5509
+ unsigned char uc1 = {5}; // OK, no narrowing needed
5510
+ unsigned char uc2 = {-1}; // error: narrows
5511
+ unsigned int ui1 = {-1}; // error: narrows
5512
+ signed int si1 =
5513
+ { (unsigned int)-1 }; // error: narrows
5514
+ int ii = {2.0}; // error: narrows
5515
+ float f1 { x }; // error: potentially narrows
5516
+ float f2 { 7 }; // OK, 7 can be exactly represented as a float
5517
+ bool b = {"meow"}; // error: narrows
5518
+ int f(int);
5519
+ int a[] = { 2, f(2), f(2.0) }; // OK, the double-to-int conversion is not at the top level
5520
+ ```
5521
+
5522
+ — *end example*]
5523
+
5524
+ ## Function definitions <a id="dcl.fct.def">[[dcl.fct.def]]</a>
5525
+
5526
+ ### General <a id="dcl.fct.def.general">[[dcl.fct.def.general]]</a>
5527
+
5528
+ Function definitions have the form
5529
+
5530
+ ``` bnf
5531
+ function-definition:
5532
+ attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator virt-specifier-seqₒₚₜ
5533
+ function-contract-specifier-seqₒₚₜ function-body
5534
+ attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator requires-clause
5535
+ function-contract-specifier-seqₒₚₜ function-body
5536
+ ```
5537
+
5538
+ ``` bnf
5539
+ function-body:
5540
+ ctor-initializerₒₚₜ compound-statement
5541
+ function-try-block
5542
+ '=' default ';'
5543
+ deleted-function-body
5544
+ ```
5545
+
5546
+ ``` bnf
5547
+ deleted-function-body:
5548
+ '=' delete ';'
5549
+ '=' delete '(' unevaluated-string ')' ';'
5550
+ ```
5551
+
5552
+ Any informal reference to the body of a function should be interpreted
5553
+ as a reference to the non-terminal *function-body*, including, for a
5554
+ constructor, default member initializers or default initialization used
5555
+ to initialize a base or member subobject in the absence of a
5556
+ *mem-initializer-id* [[class.base.init]]. The optional
5557
+ *attribute-specifier-seq* in a *function-definition* appertains to the
5558
+ function. A *function-definition* with a *virt-specifier-seq* shall be a
5559
+ *member-declaration* [[class.mem]]. A *function-definition* with a
5560
+ *requires-clause* shall define a templated function.
5561
+
5562
+ In a *function-definition*, either `void` *declarator* `;` or
5563
+ *declarator* `;` shall be a well-formed function declaration as
5564
+ described in  [[dcl.fct]]. A function shall be defined only in namespace
5565
+ or class scope. The type of a parameter or the return type for a
5566
+ function definition shall not be a (possibly cv-qualified) class type
5567
+ that is incomplete or abstract within the function body unless the
5568
+ function is deleted [[dcl.fct.def.delete]].
5569
+
5570
+ [*Example 1*:
5571
+
5572
+ A simple example of a complete function definition is
5573
+
5574
+ ``` cpp
5575
+ int max(int a, int b, int c) {
5576
+ int m = (a > b) ? a : b;
5577
+ return (m > c) ? m : c;
5578
+ }
5579
+ ```
5580
+
5581
+ Here `int` is the *decl-specifier-seq*; `max(int` `a,` `int` `b,` `int`
5582
+ `c)` is the *declarator*; `{ /* ... */ }` is the *function-body*.
5583
+
5584
+ — *end example*]
5585
+
5586
+ A *ctor-initializer* is used only in a constructor; see  [[class.ctor]]
5587
+ and  [[class.init]].
5588
+
5589
+ [*Note 1*: A *cv-qualifier-seq* affects the type of `this` in the body
5590
+ of a member function; see  [[expr.prim.this]]. — *end note*]
5591
+
5592
+ [*Note 2*:
5593
+
5594
+ Unused parameters need not be named. For example,
5595
+
5596
+ ``` cpp
5597
+ void print(int a, int) {
5598
+ std::printf("a = %d\n",a);
5599
+ }
5600
+ ```
5601
+
5602
+ — *end note*]
5603
+
5604
+ A *function-local predefined variable* is a variable with static storage
5605
+ duration that is implicitly defined in a function parameter scope.
5606
+
5607
+ The function-local predefined variable `__func__` is defined as if a
5608
+ definition of the form
5609
+
5610
+ ``` cpp
5611
+ static const char __func__[] = "function-name";
5612
+ ```
5613
+
5614
+ had been provided, where `function-name` is an *implementation-defined*
5615
+ string. It is unspecified whether such a variable has an address
5616
+ distinct from that of any other object in the program.[^8]
5617
+
5618
+ [*Example 2*:
5619
+
5620
+ ``` cpp
5621
+ struct S {
5622
+ S() : s(__func__) { } // OK
5623
+ const char* s;
5624
+ };
5625
+ void f(const char* s = __func__); // error: __func__ is undeclared
5626
+ ```
5627
+
5628
+ — *end example*]
5629
+
5630
+ ### Explicitly-defaulted functions <a id="dcl.fct.def.default">[[dcl.fct.def.default]]</a>
5631
+
5632
+ A function definition whose *function-body* is of the form `= default ;`
5633
+ is called an *explicitly-defaulted* definition. A function that is
5634
+ explicitly defaulted shall
5635
+
5636
+ - be a special member function [[special]] or a comparison operator
5637
+ function [[over.binary]], [[class.compare.default]], and
5638
+ - not have default arguments [[dcl.fct.default]].
5639
+
5640
+ An explicitly defaulted special member function `F₁` is allowed to
5641
+ differ from the corresponding special member function `F₂` that would
5642
+ have been implicitly declared, as follows:
5643
+
5644
+ - `F₁` and `F₂` may have differing *ref-qualifier*s;
5645
+ - if `F₂` has an implicit object parameter of type “reference to `C`”,
5646
+ `F₁` may be an explicit object member function whose explicit object
5647
+ parameter is of (possibly different) type “reference to `C`”, in which
5648
+ case the type of `F₁` would differ from the type of `F₂` in that the
5649
+ type of `F₁` has an additional parameter;
5650
+ - `F₁` and `F₂` may have differing exception specifications; and
5651
+ - if `F₂` has a non-object parameter of type `const C&`, the
5652
+ corresponding non-object parameter of `F₁` may be of type `C&`.
5653
+
5654
+ If the type of `F₁` differs from the type of `F₂` in a way other than as
5655
+ allowed by the preceding rules, then:
5656
+
5657
+ - if `F₁` is an assignment operator, and the return type of `F₁` differs
5658
+ from the return type of `F₂` or `F₁`’s non-object parameter type is
5659
+ not a reference, the program is ill-formed;
5660
+ - otherwise, if `F₁` is explicitly defaulted on its first declaration,
5661
+ it is defined as deleted;
5662
+ - otherwise, the program is ill-formed.
5663
+
5664
+ A function explicitly defaulted on its first declaration is implicitly
5665
+ inline [[dcl.inline]], and is implicitly constexpr [[dcl.constexpr]] if
5666
+ it is constexpr-suitable.
5667
+
5668
+ [*Note 1*: Other defaulted functions are not implicitly
5669
+ constexpr. — *end note*]
5670
+
5671
+ [*Example 1*:
5672
+
5673
+ ``` cpp
5674
+ struct S {
5675
+ S(int a = 0) = default; // error: default argument
5676
+ void operator=(const S&) = default; // error: non-matching return type
5677
+ ~S() noexcept(false) = default; // OK, despite mismatched exception specification
5678
+ private:
5679
+ int i;
5680
+ S(S&); // OK, private copy constructor
5681
+ };
5682
+ S::S(S&) = default; // OK, defines copy constructor
5683
+
5684
+ struct T {
5685
+ T();
5686
+ T(T &&) noexcept(false);
5687
+ };
5688
+ struct U {
5689
+ T t;
5690
+ U();
5691
+ U(U &&) noexcept = default;
5692
+ };
5693
+ U u1;
5694
+ U u2 = static_cast<U&&>(u1); // OK, calls std::terminate if T::T(T&&) throws
5695
+ ```
5696
+
5697
+ — *end example*]
5698
+
5699
+ Explicitly-defaulted functions and implicitly-declared functions are
5700
+ collectively called *defaulted* functions, and the implementation shall
5701
+ provide implicit definitions for them
5702
+ [[class.ctor]], [[class.dtor]], [[class.copy.ctor]], [[class.copy.assign]]
5703
+ as described below, including possibly defining them as deleted. A
5704
+ defaulted prospective destructor [[class.dtor]] that is not a destructor
5705
+ is defined as deleted. A defaulted special member function that is
5706
+ neither a prospective destructor nor an eligible special member function
5707
+ [[special]] is defined as deleted. A function is *user-provided* if it
5708
+ is user-declared and not explicitly defaulted or deleted on its first
5709
+ declaration. A user-provided explicitly-defaulted function (i.e.,
5710
+ explicitly defaulted after its first declaration) is implicitly defined
5711
+ at the point where it is explicitly defaulted; if such a function is
5712
+ implicitly defined as deleted, the program is ill-formed.
5713
+
5714
+ [*Note 2*: Declaring a function as defaulted after its first
5715
+ declaration can provide efficient execution and concise definition while
5716
+ enabling a stable binary interface to an evolving code
5717
+ base. — *end note*]
5718
+
5719
+ A non-user-provided defaulted function (i.e., implicitly declared or
5720
+ explicitly defaulted in the class) that is not defined as deleted is
5721
+ implicitly defined when it is odr-used [[basic.def.odr]] or needed for
5722
+ constant evaluation [[expr.const]].
5723
+
5724
+ [*Note 3*: The implicit definition of a non-user-provided defaulted
5725
+ function does not bind any names. — *end note*]
5726
+
5727
+ [*Example 2*:
5728
+
5729
+ ``` cpp
5730
+ struct trivial {
5731
+ trivial() = default;
5732
+ trivial(const trivial&) = default;
5733
+ trivial(trivial&&) = default;
5734
+ trivial& operator=(const trivial&) = default;
5735
+ trivial& operator=(trivial&&) = default;
5736
+ ~trivial() = default;
5737
+ };
5738
+
5739
+ struct nontrivial1 {
5740
+ nontrivial1();
5741
+ };
5742
+ nontrivial1::nontrivial1() = default; // not first declaration
5743
+ ```
5744
+
5745
+ — *end example*]
5746
+
5747
+ ### Deleted definitions <a id="dcl.fct.def.delete">[[dcl.fct.def.delete]]</a>
5748
+
5749
+ A *deleted definition* of a function is a function definition whose
5750
+ *function-body* is a *deleted-function-body* or an explicitly-defaulted
5751
+ definition of the function where the function is defined as deleted. A
5752
+ *deleted function* is a function with a deleted definition or a function
5753
+ that is implicitly defined as deleted.
5754
+
5755
+ A construct that designates a deleted function implicitly or explicitly,
5756
+ other than to declare it or to appear as the operand of a
5757
+ *reflect-expression* [[expr.reflect]], is ill-formed.
5758
+
5759
+ *Recommended practice:* The resulting diagnostic message should include
5760
+ the text of the *unevaluated-string*, if one is supplied.
5761
+
5762
+ [*Note 1*: This includes calling the function implicitly or explicitly
5763
+ and forming a pointer or pointer-to-member to the function. It applies
5764
+ even for references in expressions that are not potentially-evaluated.
5765
+ For an overload set, only the function selected by overload resolution
5766
+ is referenced. The implicit odr-use [[term.odr.use]] of a virtual
5767
+ function does not, by itself, constitute a reference. The
5768
+ *unevaluated-string*, if present, can be used to explain the rationale
5769
+ for deletion and/or to suggest an alternative. — *end note*]
5770
+
5771
+ [*Example 1*:
5772
+
5773
+ One can prevent default initialization and initialization by
5774
+ non-`double`s with
5775
+
5776
+ ``` cpp
5777
+ struct onlydouble {
5778
+ onlydouble() = delete; // OK, but redundant
5779
+ template<class T>
5780
+ onlydouble(T) = delete;
5781
+ onlydouble(double);
5782
+ };
5783
+ ```
5784
+
5785
+ — *end example*]
5786
+
5787
+ [*Example 2*:
5788
+
5789
+ One can prevent use of a class in certain *new-expression*s by using
5790
+ deleted definitions of a user-declared `operator new` for that class.
5791
+
5792
+ ``` cpp
5793
+ struct sometype {
5794
+ void* operator new(std::size_t) = delete;
5795
+ void* operator new[](std::size_t) = delete;
5796
+ };
5797
+ sometype* p = new sometype; // error: deleted class operator new
5798
+ sometype* q = new sometype[3]; // error: deleted class operator new[]
5799
+ ```
5800
+
5801
+ — *end example*]
5802
+
5803
+ [*Example 3*:
5804
+
5805
+ One can make a class uncopyable, i.e., move-only, by using deleted
5806
+ definitions of the copy constructor and copy assignment operator, and
5807
+ then providing defaulted definitions of the move constructor and move
5808
+ assignment operator.
5809
+
5810
+ ``` cpp
5811
+ struct moveonly {
5812
+ moveonly() = default;
5813
+ moveonly(const moveonly&) = delete;
5814
+ moveonly(moveonly&&) = default;
5815
+ moveonly& operator=(const moveonly&) = delete;
5816
+ moveonly& operator=(moveonly&&) = default;
5817
+ ~moveonly() = default;
5818
+ };
5819
+ moveonly* p;
5820
+ moveonly q(*p); // error: deleted copy constructor
5821
+ ```
5822
+
5823
+ — *end example*]
5824
+
5825
+ A deleted function is implicitly an inline function [[dcl.inline]].
5826
+
5827
+ [*Note 2*: The one-definition rule [[basic.def.odr]] applies to deleted
5828
+ definitions. — *end note*]
5829
+
5830
+ A deleted definition of a function shall be the first declaration of the
5831
+ function or, for an explicit specialization of a function template, the
5832
+ first declaration of that specialization. An implicitly declared
5833
+ allocation or deallocation function [[basic.stc.dynamic]] shall not be
5834
+ defined as deleted.
5835
+
5836
+ [*Example 4*:
5837
+
5838
+ ``` cpp
5839
+ struct sometype {
5840
+ sometype();
5841
+ };
5842
+ sometype::sometype() = delete; // error: not first declaration
5843
+ ```
5844
+
5845
+ — *end example*]
5846
+
5847
+ ### Coroutine definitions <a id="dcl.fct.def.coroutine">[[dcl.fct.def.coroutine]]</a>
5848
+
5849
+ A function is a *coroutine* if its *function-body* encloses a
5850
+ *coroutine-return-statement* [[stmt.return.coroutine]], an
5851
+ *await-expression* [[expr.await]], or a *yield-expression*
5852
+ [[expr.yield]]. The *parameter-declaration-clause* of the coroutine
5853
+ shall not terminate with an ellipsis that is not part of a
5854
+ *parameter-declaration*.
5855
+
5856
+ [*Example 1*:
5857
+
5858
+ ``` cpp
5859
+ task<int> f();
5860
+
5861
+ task<void> g1() {
5862
+ int i = co_await f();
5863
+ std::cout << "f() => " << i << std::endl;
5864
+ }
5865
+
5866
+ template <typename... Args>
5867
+ task<void> g2(Args&&...) { // OK, ellipsis is a pack expansion
5868
+ int i = co_await f();
5869
+ std::cout << "f() => " << i << std::endl;
5870
+ }
5871
+
5872
+ task<void> g3(int a, ...) { // error: variable parameter list not allowed
5873
+ int i = co_await f();
5874
+ std::cout << "f() => " << i << std::endl;
5875
+ }
5876
+ ```
5877
+
5878
+ — *end example*]
5879
+
5880
+ The *promise type* of a coroutine is
5881
+ `std::coroutine_traits<R, P₁, …, Pₙ>::promise_type`, where `R` is the
5882
+ return type of the function, and `P₁` … `Pₙ` is the sequence of types of
5883
+ the non-object function parameters, preceded by the type of the object
5884
+ parameter [[dcl.fct]] if the coroutine is a non-static member function.
5885
+ The promise type shall be a class type.
5886
+
5887
+ In the following, `pᵢ` is an lvalue of type `Pᵢ`, where `p₁` denotes the
5888
+ object parameter and `p_i+1` denotes the iᵗʰ non-object function
5889
+ parameter for an implicit object member function, and `pᵢ` denotes the
5890
+ iᵗʰ function parameter otherwise. For an implicit object member
5891
+ function, `q₁` is an lvalue that denotes `*this`; any other `qᵢ` is an
5892
+ lvalue that denotes the parameter copy corresponding to `pᵢ`, as
5893
+ described below.
5894
+
5895
+ A coroutine behaves as if the top-level cv-qualifiers in all
5896
+ *parameter-declaration*s in the declarator of its *function-definition*
5897
+ were removed and its *function-body* were replaced by the following
5898
+ *replacement body*:
5899
+
5900
+ ``` bnf
5901
+ '{'
5902
+ *promise-type* promise *promise-constructor-arguments* ';'
5903
+ % FIXME: promise'.get_return_object()' ';'
5904
+ % ... except that it's not a discarded-value expression
5905
+ 'try' '{'
5906
+ 'co_await' 'promise.initial_suspend()' ';'
5907
+ function-body
5908
+ '} catch ( ... ) {'
5909
+ 'if (!initial-await-resume-called)'
5910
+ 'throw' ';'
5911
+ 'promise.unhandled_exception()' ';'
5912
+ '}'
5913
+ final-suspend ':'
5914
+ 'co_await' 'promise.final_suspend()' ';'
5915
+ '}'
5916
+ ```
5917
+
5918
+ where
5919
+
5920
+ - the *await-expression* containing the call to `initial_suspend` is the
5921
+ *initial await expression*, and
5922
+ - the *await-expression* containing the call to `final_suspend` is the
5923
+ *final await expression*, and
5924
+ - *initial-await-resume-called* is initially `false` and is set to
5925
+ `true` immediately before the evaluation of the *await-resume*
5926
+ expression [[expr.await]] of the initial await expression, and
5927
+ - *promise-type* denotes the promise type, and
5928
+ - the object denoted by the exposition-only name *`promise`* is the
5929
+ *promise object* of the coroutine, and
5930
+ - the label denoted by the name *`final-suspend`* is defined for
5931
+ exposition only [[stmt.return.coroutine]], and
5932
+ - *promise-constructor-arguments* is determined as follows: overload
5933
+ resolution is performed on a promise constructor call created by
5934
+ assembling an argument list `q₁` … `qₙ`. If a viable constructor is
5935
+ found [[over.match.viable]], then *promise-constructor-arguments* is
5936
+ `(q₁, …, qₙ)`, otherwise *promise-constructor-arguments* is empty, and
5937
+ - a coroutine is suspended at the *initial suspend point* if it is
5938
+ suspended at the initial await expression, and
5939
+ - a coroutine is suspended at a *final suspend point* if it is suspended
5940
+ - at a final await expression or
5941
+ - due to an exception exiting from `unhandled_exception()`.
5942
+
5943
+ [*Note 1*: An odr-use of a non-reference parameter in a postcondition
5944
+ assertion of a coroutine is ill-formed
5945
+ [[dcl.contract.func]]. — *end note*]
5946
+
5947
+ If searches for the names `return_void` and `return_value` in the scope
5948
+ of the promise type each find any declarations, the program is
5949
+ ill-formed.
5950
+
5951
+ [*Note 2*: If `return_void` is found, flowing off the end of a
5952
+ coroutine is equivalent to a `co_return` with no operand. Otherwise,
5953
+ flowing off the end of a coroutine results in undefined behavior
5954
+ [[stmt.return.coroutine]]. — *end note*]
5955
+
5956
+ The expression `promise.get_return_object()` is used to initialize the
5957
+ returned reference or prvalue result object of a call to a coroutine.
5958
+ The call to `get_return_object` is sequenced before the call to
5959
+ `initial_suspend` and is invoked at most once.
5960
+
5961
+ A suspended coroutine can be resumed to continue execution by invoking a
5962
+ resumption member function [[coroutine.handle.resumption]] of a
5963
+ coroutine handle [[coroutine.handle]] that refers to the coroutine. The
5964
+ evaluation that invoked a resumption member function is called the
5965
+ *resumer*. Invoking a resumption member function for a coroutine that is
5966
+ not suspended results in undefined behavior.
5967
+
5968
+ An implementation may need to allocate additional storage for a
5969
+ coroutine. This storage is known as the *coroutine state* and is
5970
+ obtained by calling a non-array allocation function
5971
+ [[basic.stc.dynamic.allocation]] as part of the replacement body. The
5972
+ allocation function’s name is looked up by searching for it in the scope
5973
+ of the promise type.
5974
+
5975
+ - If the search finds any declarations, overload resolution is performed
5976
+ on a function call created by assembling an argument list. The first
5977
+ argument is the amount of space requested, and is a prvalue of type
5978
+ `std::size_t`. The lvalues `p₁` … `pₙ` with their original types
5979
+ (including cv-qualifiers) are the successive arguments. If no viable
5980
+ function is found [[over.match.viable]], overload resolution is
5981
+ performed again on a function call created by passing just the amount
5982
+ of space required as a prvalue of type `std::size_t`.
5983
+ - If the search finds no declarations, a search is performed in the
5984
+ global scope. Overload resolution is performed on a function call
5985
+ created by passing the amount of space required as a prvalue of type
5986
+ `std::size_t`.
5987
+
5988
+ If a search for the name `get_return_object_on_allocation_failure` in
5989
+ the scope of the promise type [[class.member.lookup]] finds any
5990
+ declarations, then the result of a call to an allocation function used
5991
+ to obtain storage for the coroutine state is assumed to return `nullptr`
5992
+ if it fails to obtain storage, and if a global allocation function is
5993
+ selected, the `::operator new(size_t, nothrow_t)` form is used. The
5994
+ allocation function used in this case shall have a non-throwing
5995
+ *noexcept-specifier*. If the allocation function returns `nullptr`, the
5996
+ coroutine transfers control to the caller of the coroutine and the
5997
+ return value is obtained by a call to
5998
+ `T::get_return_object_on_allocation_failure()`, where `T` is the promise
5999
+ type.
6000
+
6001
+ [*Example 2*:
6002
+
6003
+ ``` cpp
6004
+ #include <iostream>
6005
+ #include <coroutine>
6006
+
6007
+ // ::operator new(size_t, nothrow_t) will be used if allocation is needed
6008
+ struct generator {
6009
+ struct promise_type;
6010
+ using handle = std::coroutine_handle<promise_type>;
6011
+ struct promise_type {
6012
+ int current_value;
6013
+ static auto get_return_object_on_allocation_failure() { return generator{nullptr}; }
6014
+ auto get_return_object() { return generator{handle::from_promise(*this)}; }
6015
+ auto initial_suspend() { return std::suspend_always{}; }
6016
+ auto final_suspend() noexcept { return std::suspend_always{}; }
6017
+ void unhandled_exception() { std::terminate(); }
6018
+ void return_void() {}
6019
+ auto yield_value(int value) {
6020
+ current_value = value;
6021
+ return std::suspend_always{};
6022
+ }
6023
+ };
6024
+ bool move_next() { return coro ? (coro.resume(), !coro.done()) : false; }
6025
+ int current_value() { return coro.promise().current_value; }
6026
+ generator(generator const&) = delete;
6027
+ generator(generator && rhs) : coro(rhs.coro) { rhs.coro = nullptr; }
6028
+ ~generator() { if (coro) coro.destroy(); }
6029
+ private:
6030
+ generator(handle h) : coro(h) {}
6031
+ handle coro;
6032
+ };
6033
+ generator f() { co_yield 1; co_yield 2; }
6034
+ int main() {
6035
+ auto g = f();
6036
+ while (g.move_next()) std::cout << g.current_value() << std::endl;
6037
+ }
6038
+ ```
6039
+
6040
+ — *end example*]
6041
+
6042
+ The coroutine state is destroyed when control flows off the end of the
6043
+ coroutine or the `destroy` member function
6044
+ [[coroutine.handle.resumption]] of a coroutine handle
6045
+ [[coroutine.handle]] that refers to the coroutine is invoked. In the
6046
+ latter case, control in the coroutine is considered to be transferred
6047
+ out of the function [[stmt.dcl]]. The storage for the coroutine state is
6048
+ released by calling a non-array deallocation function
6049
+ [[basic.stc.dynamic.deallocation]]. If `destroy` is called for a
6050
+ coroutine that is not suspended, the program has undefined behavior.
6051
+
6052
+ The deallocation function’s name is looked up by searching for it in the
6053
+ scope of the promise type. If nothing is found, a search is performed in
6054
+ the global scope. If both a usual deallocation function with only a
6055
+ pointer parameter and a usual deallocation function with both a pointer
6056
+ parameter and a size parameter are found, then the selected deallocation
6057
+ function shall be the one with two parameters. Otherwise, the selected
6058
+ deallocation function shall be the function with one parameter. If no
6059
+ usual deallocation function is found, the program is ill-formed. The
6060
+ selected deallocation function shall be called with the address of the
6061
+ block of storage to be reclaimed as its first argument. If a
6062
+ deallocation function with a parameter of type `std::size_t` is used,
6063
+ the size of the block is passed as the corresponding argument.
6064
+
6065
+ When a coroutine is invoked, a copy is created for each coroutine
6066
+ parameter at the beginning of the replacement body. For a parameter
6067
+ whose original declaration specified the type cv `T`,
6068
+
6069
+ - if `T` is a reference type, the copy is a reference of type cv `T`
6070
+ bound to the same object as a parameter;
6071
+ - otherwise, the copy is a variable of type cv `T` with automatic
6072
+ storage duration that is direct-initialized from an xvalue of type `T`
6073
+ referring to the parameter.
6074
+
6075
+ [*Note 3*: An identifier in the *function-body* that names one of these
6076
+ parameters refers to the created copy, not the original parameter
6077
+ [[expr.prim.id.unqual]]. — *end note*]
6078
+
6079
+ The initialization and destruction of each parameter copy occurs in the
6080
+ context of the called coroutine. Initializations of parameter copies are
6081
+ sequenced before the call to the coroutine promise constructor and
6082
+ indeterminately sequenced with respect to each other. The lifetime of
6083
+ parameter copies ends immediately after the lifetime of the coroutine
6084
+ promise object ends.
6085
+
6086
+ [*Note 4*: If a coroutine has a parameter passed by reference, resuming
6087
+ the coroutine after the lifetime of the entity referred to by that
6088
+ parameter has ended is likely to result in undefined
6089
+ behavior. — *end note*]
6090
+
6091
+ If the evaluation of the expression `promise.unhandled_exception()`
6092
+ exits via an exception, the coroutine is considered suspended at the
6093
+ final suspend point and the exception propagates to the caller or
6094
+ resumer.
6095
+
6096
+ The expression `co_await` `promise.final_suspend()` shall not be
6097
+ potentially-throwing [[except.spec]].
6098
+
6099
+ ### Replaceable function definitions <a id="dcl.fct.def.replace">[[dcl.fct.def.replace]]</a>
6100
+
6101
+ Certain functions for which a definition is supplied by the
6102
+ implementation are *replaceable*. A C++ program may provide a definition
6103
+ with the signature of a replaceable function, called a
6104
+ *replacement function*. The replacement function is used instead of the
6105
+ default version supplied by the implementation. Such replacement occurs
6106
+ prior to program startup [[basic.def.odr]], [[basic.start]]. A
6107
+ declaration of the replacement function
6108
+
6109
+ - shall not be inline,
6110
+ - shall be attached to the global module,
6111
+ - shall have C++ language linkage,
6112
+ - shall have the same return type as the replaceable function, and
6113
+ - if the function is declared in a standard library header, shall be
6114
+ such that it would be valid as a redeclaration of the declaration in
6115
+ that header;
6116
+
6117
+ no diagnostic is required.
6118
+
6119
+ [*Note 1*: The one-definition rule [[basic.def.odr]] applies to the
6120
+ definitions of a replaceable function provided by the program. The
6121
+ implementation-supplied function definition is an otherwise-unnamed
6122
+ function with no linkage. — *end note*]
6123
+
6124
+ ## Structured binding declarations <a id="dcl.struct.bind">[[dcl.struct.bind]]</a>
6125
+
6126
+ A structured binding declaration introduces the *identifier*s `v₀`,
6127
+ `v₁`, `v₂`, …, `v_N-1` of the *sb-identifier-list* as names. An
6128
+ *sb-identifier* that contains an ellipsis introduces a structured
6129
+ binding pack [[temp.variadic]]. A *structured binding* is either an
6130
+ *sb-identifier* that does not contain an ellipsis or an element of a
6131
+ structured binding pack. The optional *attribute-specifier-seq* of an
6132
+ *sb-identifier* appertains to the associated structured bindings. Let cv
6133
+ denote the *cv-qualifier*s in the *decl-specifier-seq* and *S* consist
6134
+ of each *decl-specifier* of the *decl-specifier-seq* that is
6135
+ `constexpr`, `constinit`, or a *storage-class-specifier*. A cv that
6136
+ includes `volatile` is deprecated; see  [[depr.volatile.type]]. First, a
6137
+ variable with a unique name *`e`* is introduced. If the
6138
+ *assignment-expression* in the *initializer* has array type *cv1* `A`
6139
+ and no *ref-qualifier* is present, *`e`* is defined by
6140
+
6141
+ ``` bnf
6142
+ attribute-specifier-seqₒₚₜ *S* cv 'A' e ';'
6143
+ ```
6144
+
6145
+ and each element is copy-initialized or direct-initialized from the
6146
+ corresponding element of the *assignment-expression* as specified by the
6147
+ form of the *initializer*. Otherwise, *`e`* is defined as-if by
6148
+
6149
+ ``` bnf
6150
+ attribute-specifier-seqₒₚₜ decl-specifier-seq ref-qualifierₒₚₜ e initializer ';'
6151
+ ```
6152
+
6153
+ where the declaration is never interpreted as a function declaration and
6154
+ the parts of the declaration other than the *declarator-id* are taken
6155
+ from the corresponding structured binding declaration. The type of the
6156
+ *id-expression* *`e`* is called `E`.
6157
+
6158
+ [*Note 1*: `E` is never a reference type [[expr.prop]]. — *end note*]
6159
+
6160
+ The *structured binding size* of `E`, as defined below, is the number of
6161
+ structured bindings that need to be introduced by the structured binding
6162
+ declaration. If there is no structured binding pack, then the number of
6163
+ elements in the *sb-identifier-list* shall be equal to the structured
6164
+ binding size of `E`. Otherwise, the number of non-pack elements shall be
6165
+ no more than the structured binding size of `E`; the number of elements
6166
+ of the structured binding pack is the structured binding size of `E`
6167
+ less the number of non-pack elements in the *sb-identifier-list*.
6168
+
6169
+ Let $\textrm{SB}_i$ denote the $i^\textrm{th}$ structured binding in the
6170
+ structured binding declaration after expanding the structured binding
6171
+ pack, if any.
6172
+
6173
+ [*Note 2*: If there is no structured binding pack, then $\textrm{SB}_i$
6174
+ denotes `vᵢ`. — *end note*]
6175
+
6176
+ [*Example 1*:
6177
+
6178
+ ``` cpp
6179
+ struct C { int x, y, z; };
6180
+
6181
+ template<class T>
6182
+ void now_i_know_my() {
6183
+ auto [a, b, c] = C(); // OK, $SB_0$ is a, $SB_1$ is b, and $SB_2$ is c
6184
+ auto [d, ...e] = C(); // OK, $SB_0$ is d, the pack e (`v`_1) contains two structured bindings: $SB_1$ and $SB_2$
6185
+ auto [...f, g] = C(); // OK, the pack f (`v`_0) contains two structured bindings: $SB_0$ and $SB_1$, and $SB_2$ is g
6186
+ auto [h, i, j, ...k] = C(); // OK, the pack k is empty
6187
+ auto [l, m, n, o, ...p] = C(); // error: structured binding size is too small
6188
+ }
6189
+ ```
6190
+
6191
+ — *end example*]
6192
+
6193
+ If a structured binding declaration appears as a *condition*, the
6194
+ decision variable [[stmt.pre]] of the condition is *`e`*.
6195
+
6196
+ If the *initializer* refers to one of the names introduced by the
6197
+ structured binding declaration, the program is ill-formed.
6198
+
6199
+ `E` shall not be an array type of unknown bound. If `E` is any other
6200
+ array type with element type `T`, the structured binding size of `E` is
6201
+ equal to the number of elements of `E`. Each $\textrm{SB}_i$ is the name
6202
+ of an lvalue that refers to the element i of the array and whose type is
6203
+ `T`; the referenced type is `T`.
6204
+
6205
+ [*Note 3*: The top-level cv-qualifiers of `T` are cv. — *end note*]
6206
+
6207
+ [*Example 2*:
6208
+
6209
+ ``` cpp
6210
+ auto f() -> int(&)[2];
6211
+ auto [ x, y ] = f(); // x and y refer to elements in a copy of the array return value
6212
+ auto& [ xr, yr ] = f(); // xr and yr refer to elements in the array referred to by f's return value
6213
+
6214
+ auto g() -> int(&)[4];
6215
+
6216
+ template<size_t N>
6217
+ void h(int (&arr)[N]) {
6218
+ auto [a, ...b, c] = arr; // a names the first element of the array, b is a pack referring to the second and
6219
+ // third elements, and c names the fourth element
6220
+ auto& [...e] = arr; // e is a pack referring to the four elements of the array
6221
+ }
6222
+
6223
+ void call_h() {
6224
+ h(g());
6225
+ }
6226
+ ```
6227
+
6228
+ — *end example*]
6229
+
6230
+ Otherwise, if the *qualified-id* `std::tuple_size<E>` names a complete
6231
+ class type with a member named `value`, the expression
6232
+ `std::tuple_size<E>::value` shall be a well-formed integral constant
6233
+ expression and the structured binding size of `E` is equal to the value
6234
+ of that expression. Let `i` be an index prvalue of type `std::size_t`
6235
+ corresponding to `vᵢ`. If a search for the name `get` in the scope of
6236
+ `E` [[class.member.lookup]] finds at least one declaration that is a
6237
+ function template whose first template parameter is a constant template
6238
+ parameter, the initializer is `e.get<i>()`. Otherwise, the initializer
6239
+ is `get<i>(e)`, where `get` undergoes argument-dependent lookup
6240
+ [[basic.lookup.argdep]]. In either case, `get<i>` is interpreted as a
6241
+ *template-id*.
6242
+
6243
+ [*Note 4*: Ordinary unqualified lookup [[basic.lookup.unqual]] is not
6244
+ performed. — *end note*]
6245
+
6246
+ In either case, *`e`* is an lvalue if the type of the entity *`e`* is an
6247
+ lvalue reference and an xvalue otherwise. Given the type `Tᵢ` designated
6248
+ by `std::tuple_element<i, E>::type` and the type `Uᵢ` designated by
6249
+ either `Tᵢ&` or `Tᵢ&&`, where `Uᵢ` is an lvalue reference if the
6250
+ initializer is an lvalue and an rvalue reference otherwise, variables
6251
+ are introduced with unique names `rᵢ` as follows:
6252
+
6253
+ ``` bnf
6254
+ *S* 'Uᵢ rᵢ =' initializer ';'
6255
+ ```
6256
+
6257
+ Each $\textrm{SB}_i$ is the name of an lvalue of type `Tᵢ` that refers
6258
+ to the object bound to `rᵢ`; the referenced type is `Tᵢ`. The
6259
+ initialization of *`e`* and any conversion of *`e`* considered as a
6260
+ decision variable [[stmt.pre]] is sequenced before the initialization of
6261
+ any `rᵢ`. The initialization of each `rᵢ` is sequenced before the
6262
+ initialization of any `rⱼ` where i < j.
6263
+
6264
+ Otherwise, all of `E`’s non-static data members shall be direct members
6265
+ of `E` or of the same base class of `E`, well-formed when named as
6266
+ `e.name` in the context of the structured binding, `E` shall not have an
6267
+ anonymous union member, and the structured binding size of `E` is equal
6268
+ to the number of non-static data members of `E`. Designating the
6269
+ non-static data members of `E` as `m₀`, `m₁`, `m₂`, … (in declaration
6270
+ order), each $\textrm{SB}_i$ is the name of an lvalue that refers to the
6271
+ member `m`ᵢ of *`e`* and whose type is that of `e.mᵢ` [[expr.ref]]; the
6272
+ referenced type is the declared type of `mᵢ` if that type is a reference
6273
+ type, or the type of `e.mᵢ` otherwise. The lvalue is a bit-field if that
6274
+ member is a bit-field.
6275
+
6276
+ [*Example 3*:
6277
+
6278
+ ``` cpp
6279
+ struct S { mutable int x1 : 2; volatile double y1; };
6280
+ S f();
6281
+ const auto [ x, y ] = f();
6282
+ ```
6283
+
6284
+ The type of the *id-expression* `x` is “`int`”, the type of the
6285
+ *id-expression* `y` is “`const volatile double`”.
6286
+
6287
+ — *end example*]
6288
+
6289
+ ## Enumerations <a id="enum">[[enum]]</a>
6290
+
6291
+ ### Enumeration declarations <a id="dcl.enum">[[dcl.enum]]</a>
6292
+
6293
+ An enumeration is a distinct type [[basic.compound]] with named
6294
+ constants. Its name becomes an *enum-name* within its scope.
6295
+
6296
+ ``` bnf
6297
+ enum-name:
6298
+ identifier
6299
+ ```
6300
+
6301
+ ``` bnf
6302
+ enum-specifier:
6303
+ enum-head '{' enumerator-listₒₚₜ '}'
6304
+ enum-head '{' enumerator-list ',' '}'
6305
+ ```
6306
+
6307
+ ``` bnf
6308
+ enum-head:
6309
+ enum-key attribute-specifier-seqₒₚₜ enum-head-nameₒₚₜ enum-baseₒₚₜ
6310
+ ```
6311
+
6312
+ ``` bnf
6313
+ enum-head-name:
6314
+ nested-name-specifierₒₚₜ identifier
6315
+ ```
6316
+
6317
+ ``` bnf
6318
+ opaque-enum-declaration:
6319
+ enum-key attribute-specifier-seqₒₚₜ enum-head-name enum-baseₒₚₜ ';'
6320
+ ```
6321
+
6322
+ ``` bnf
6323
+ enum-key:
6324
+ enum
6325
+ enum class
6326
+ enum struct
6327
+ ```
6328
+
6329
+ ``` bnf
6330
+ enum-base:
6331
+ ':' type-specifier-seq
6332
+ ```
6333
+
6334
+ ``` bnf
6335
+ enumerator-list:
6336
+ enumerator-definition
6337
+ enumerator-list ',' enumerator-definition
6338
+ ```
6339
+
6340
+ ``` bnf
6341
+ enumerator-definition:
6342
+ enumerator
6343
+ enumerator '=' constant-expression
6344
+ ```
6345
+
6346
+ ``` bnf
6347
+ enumerator:
6348
+ identifier attribute-specifier-seqₒₚₜ
6349
+ ```
6350
+
6351
+ The optional *attribute-specifier-seq* in the *enum-head* and the
6352
+ *opaque-enum-declaration* appertains to the enumeration; the attributes
6353
+ in that *attribute-specifier-seq* are thereafter considered attributes
6354
+ of the enumeration whenever it is named. A `:` following “`enum`
6355
+ *nested-name-specifier*ₒₚₜ *identifier*” within the
6356
+ *decl-specifier-seq* of a *member-declaration* is parsed as part of an
6357
+ *enum-base*.
6358
+
6359
+ [*Note 1*:
6360
+
6361
+ This resolves a potential ambiguity between the declaration of an
6362
+ enumeration with an *enum-base* and the declaration of an unnamed
6363
+ bit-field of enumeration type.
6364
+
6365
+ [*Example 1*:
6366
+
6367
+ ``` cpp
6368
+ struct S {
6369
+ enum E : int {};
6370
+ enum E : int {}; // error: redeclaration of enumeration
6371
+ };
6372
+ ```
6373
+
6374
+ — *end example*]
6375
+
6376
+ — *end note*]
6377
+
6378
+ The *identifier* in an *enum-head-name* is not looked up and is
6379
+ introduced by the *enum-specifier* or *opaque-enum-declaration*. If the
6380
+ *enum-head-name* of an *opaque-enum-declaration* contains a
6381
+ *nested-name-specifier*, the declaration shall be an explicit
6382
+ specialization [[temp.expl.spec]].
6383
+
6384
+ The enumeration type declared with an *enum-key* of only `enum` is an
6385
+ *unscoped enumeration*, and its *enumerator*s are *unscoped
6386
+ enumerators*. The *enum-key*s `enum class` and `enum struct` are
6387
+ semantically equivalent; an enumeration type declared with one of these
6388
+ is a *scoped enumeration*, and its *enumerator*s are *scoped
6389
+ enumerators*. The optional *enum-head-name* shall not be omitted in the
6390
+ declaration of a scoped enumeration. The *type-specifier-seq* of an
6391
+ *enum-base* shall name an integral type; any cv-qualification is
6392
+ ignored. An *opaque-enum-declaration* declaring an unscoped enumeration
6393
+ shall not omit the *enum-base*. The identifiers in an *enumerator-list*
6394
+ are declared as constants, and can appear wherever constants are
6395
+ required. The same identifier shall not appear as the name of multiple
6396
+ enumerators in an *enumerator-list*. An *enumerator-definition* with `=`
6397
+ gives the associated *enumerator* the value indicated by the
6398
+ *constant-expression*. An *enumerator-definition* without `=` gives the
6399
+ associated *enumerator* the value zero if it is the first
6400
+ *enumerator-definition*, and the value of the previous *enumerator*
6401
+ increased by one otherwise.
6402
+
6403
+ [*Example 2*:
6404
+
6405
+ ``` cpp
6406
+ enum { a, b, c=0 };
6407
+ enum { d, e, f=e+2 };
6408
+ ```
6409
+
6410
+ defines `a`, `c`, and `d` to be zero, `b` and `e` to be `1`, and `f` to
6411
+ be `3`.
6412
+
6413
+ — *end example*]
6414
+
6415
+ The optional *attribute-specifier-seq* in an *enumerator* appertains to
6416
+ that enumerator.
6417
+
6418
+ An *opaque-enum-declaration* is either a redeclaration of an enumeration
6419
+ in the current scope or a declaration of a new enumeration.
6420
+
6421
+ [*Note 2*: An enumeration declared by an *opaque-enum-declaration* has
6422
+ a fixed underlying type and is a complete type. The list of enumerators
6423
+ can be provided in a later redeclaration with an
6424
+ *enum-specifier*. — *end note*]
6425
+
6426
+ A scoped enumeration shall not be later redeclared as unscoped or with a
6427
+ different underlying type. An unscoped enumeration shall not be later
6428
+ redeclared as scoped and each redeclaration shall include an *enum-base*
6429
+ specifying the same underlying type as in the original declaration.
6430
+
6431
+ If an *enum-head-name* contains a *nested-name-specifier*, the enclosing
6432
+ *enum-specifier* or *opaque-enum-declaration* D shall not inhabit a
6433
+ class scope and shall correspond to one or more declarations nominable
6434
+ in the class, class template, or namespace to which the
6435
+ *nested-name-specifier* refers [[basic.scope.scope]]. All those
6436
+ declarations shall have the same target scope; the target scope of D is
6437
+ that scope.
6438
+
6439
+ Each enumeration defines a type that is different from all other types.
6440
+ Each enumeration also has an *underlying type*. The underlying type can
6441
+ be explicitly specified using an *enum-base*. For a scoped enumeration
6442
+ type, the underlying type is `int` if it is not explicitly specified. In
6443
+ both of these cases, the underlying type is said to be *fixed*.
6444
+ Following the closing brace of an *enum-specifier*, each enumerator has
6445
+ the type of its enumeration. If the underlying type is fixed, the type
6446
+ of each enumerator prior to the closing brace is the underlying type and
6447
+ the *constant-expression* in the *enumerator-definition* shall be a
6448
+ converted constant expression of the underlying type [[expr.const]]. If
6449
+ the underlying type is not fixed, the type of each enumerator prior to
6450
+ the closing brace is determined as follows:
6451
+
6452
+ - If an initializer is specified for an enumerator, the
6453
+ *constant-expression* shall be an integral constant expression
6454
+ [[expr.const]]. If the expression has unscoped enumeration type, the
6455
+ enumerator has the underlying type of that enumeration type, otherwise
6456
+ it has the same type as the expression.
6457
+ - If no initializer is specified for the first enumerator, its type is
6458
+ an unspecified signed integral type.
6459
+ - Otherwise the type of the enumerator is the same as that of the
6460
+ preceding enumerator unless the incremented value is not representable
6461
+ in that type, in which case the type is an unspecified integral type
6462
+ sufficient to contain the incremented value. If no such type exists,
6463
+ the program is ill-formed.
6464
+
6465
+ An enumeration whose underlying type is fixed is an incomplete type
6466
+ until immediately after its *enum-base* (if any), at which point it
6467
+ becomes a complete type. An enumeration whose underlying type is not
6468
+ fixed is an incomplete type until the closing `}` of its
6469
+ *enum-specifier*, at which point it becomes a complete type.
6470
+
6471
+ For an enumeration whose underlying type is not fixed, the underlying
6472
+ type is an integral type that can represent all the enumerator values
6473
+ defined in the enumeration. If no integral type can represent all the
6474
+ enumerator values, the enumeration is ill-formed. It is
6475
+ *implementation-defined* which integral type is used as the underlying
6476
+ type except that the underlying type shall not be larger than `int`
6477
+ unless the value of an enumerator cannot fit in an `int` or
6478
+ `unsigned int`. If the *enumerator-list* is empty, the underlying type
6479
+ is as if the enumeration had a single enumerator with value 0.
6480
+
6481
+ For an enumeration whose underlying type is fixed, the values of the
6482
+ enumeration are the values of the underlying type. Otherwise, the values
6483
+ of the enumeration are the values representable by a hypothetical
6484
+ integer type with minimal width M such that all enumerators can be
6485
+ represented. The width of the smallest bit-field large enough to hold
6486
+ all the values of the enumeration type is M. It is possible to define an
6487
+ enumeration that has values not defined by any of its enumerators. If
6488
+ the *enumerator-list* is empty, the values of the enumeration are as if
6489
+ the enumeration had a single enumerator with value 0.[^9]
6490
+
6491
+ An enumeration has the same size, value representation, and alignment
6492
+ requirements [[basic.align]] as its underlying type. Furthermore, each
6493
+ value of an enumeration has the same representation as the corresponding
6494
+ value of the underlying type.
6495
+
6496
+ Two enumeration types are *layout-compatible enumerations* if they have
6497
+ the same underlying type.
6498
+
6499
+ The value of an enumerator or an object of an unscoped enumeration type
6500
+ is converted to an integer by integral promotion [[conv.prom]].
6501
+
6502
+ [*Example 3*:
6503
+
6504
+ ``` cpp
6505
+ enum color { red, yellow, green=20, blue };
6506
+ color col = red;
6507
+ color* cp = &col;
6508
+ if (*cp == blue) // ...
6509
+ ```
6510
+
6511
+ makes `color` a type describing various colors, and then declares `col`
6512
+ as an object of that type, and `cp` as a pointer to an object of that
6513
+ type. The possible values of an object of type `color` are `red`,
6514
+ `yellow`, `green`, `blue`; these values can be converted to the integral
6515
+ values `0`, `1`, `20`, and `21`. Since enumerations are distinct types,
6516
+ objects of type `color` can be assigned only values of type `color`.
6517
+
6518
+ ``` cpp
6519
+ color c = 1; // error: type mismatch, no conversion from int to color
6520
+ int i = yellow; // OK, yellow converted to integral value 1, integral promotion
6521
+ ```
6522
+
6523
+ Note that this implicit `enum` to `int` conversion is not provided for a
6524
+ scoped enumeration:
6525
+
6526
+ ``` cpp
6527
+ enum class Col { red, yellow, green };
6528
+ int x = Col::red; // error: no Col to int conversion
6529
+ Col y = Col::red;
6530
+ if (y) { } // error: no Col to bool conversion
6531
+ ```
6532
+
6533
+ — *end example*]
6534
+
6535
+ The name of each unscoped enumerator is also bound in the scope that
6536
+ immediately contains the *enum-specifier*. An unnamed enumeration that
6537
+ does not have a typedef name for linkage purposes [[dcl.typedef]] and
6538
+ that has a first enumerator is denoted, for linkage purposes
6539
+ [[basic.link]], by its underlying type and its first enumerator; such an
6540
+ enumeration is said to have an enumerator as a name for linkage
6541
+ purposes.
6542
+
6543
+ [*Note 3*: Each unnamed enumeration with no enumerators is a distinct
6544
+ type. — *end note*]
6545
+
6546
+ [*Example 4*:
6547
+
6548
+ ``` cpp
6549
+ enum direction { left='l', right='r' };
6550
+
6551
+ void g() {
6552
+ direction d; // OK
6553
+ d = left; // OK
6554
+ d = direction::right; // OK
6555
+ }
6556
+
6557
+ enum class altitude { high='h', low='l' };
6558
+
6559
+ void h() {
6560
+ altitude a; // OK
6561
+ a = high; // error: high not in scope
6562
+ a = altitude::low; // OK
6563
+ }
6564
+ ```
6565
+
6566
+ — *end example*]
6567
+
6568
+ ### The `using enum` declaration <a id="enum.udecl">[[enum.udecl]]</a>
6569
+
6570
+ ``` bnf
6571
+ using-enum-declaration:
6572
+ using enum using-enum-declarator ';'
6573
+ ```
6574
+
6575
+ ``` bnf
6576
+ using-enum-declarator:
6577
+ nested-name-specifierₒₚₜ identifier
6578
+ nested-name-specifierₒₚₜ simple-template-id
6579
+ splice-type-specifier
6580
+ ```
6581
+
6582
+ A *using-enum-declarator* of the form *splice-type-specifier* designates
6583
+ the same type designated by the *splice-type-specifier*. Any other
6584
+ *using-enum-declarator* names the set of declarations found by type-only
6585
+ lookup [[basic.lookup.general]] for the *using-enum-declarator*
6586
+ [[basic.lookup.unqual]], [[basic.lookup.qual]]. The
6587
+ *using-enum-declarator* shall designate a non-dependent type with a
6588
+ reachable *enum-specifier*.
6589
+
6590
+ [*Example 1*:
6591
+
6592
+ ``` cpp
6593
+ enum E { x };
6594
+ void f() {
6595
+ int E;
6596
+ using enum E; // OK
6597
+ }
6598
+ using F = E;
6599
+ using enum F; // OK
6600
+ template<class T> using EE = T;
6601
+ void g() {
6602
+ using enum EE<E>; // OK
6603
+ }
6604
+ ```
6605
+
6606
+ — *end example*]
6607
+
6608
+ A *using-enum-declaration* is equivalent to a *using-declaration* for
6609
+ each enumerator.
6610
+
6611
+ [*Note 1*:
6612
+
6613
+ A *using-enum-declaration* in class scope makes the enumerators of the
6614
+ named enumeration available via member lookup.
6615
+
6616
+ [*Example 2*:
6617
+
6618
+ ``` cpp
6619
+ enum class fruit { orange, apple };
6620
+ struct S {
6621
+ using enum fruit; // OK, introduces orange and apple into S
6622
+ };
6623
+ void f() {
6624
+ S s;
6625
+ s.orange; // OK, names fruit::orange
6626
+ S::orange; // OK, names fruit::orange
6627
+ }
6628
+ ```
6629
+
6630
+ — *end example*]
6631
+
6632
+ — *end note*]
6633
+
6634
+ [*Note 2*:
6635
+
6636
+ Two *using-enum-declaration*s that introduce two enumerators of the same
6637
+ name conflict.
6638
+
6639
+ [*Example 3*:
6640
+
6641
+ ``` cpp
6642
+ enum class fruit { orange, apple };
6643
+ enum class color { red, orange };
6644
+ void f() {
6645
+ using enum fruit; // OK
6646
+ using enum color; // error: color::orange and fruit::orange conflict
6647
+ }
6648
+ ```
6649
+
6650
+ — *end example*]
6651
+
6652
+ — *end note*]
6653
+
6654
+ ## Namespaces <a id="basic.namespace">[[basic.namespace]]</a>
6655
+
6656
+ ### General <a id="basic.namespace.general">[[basic.namespace.general]]</a>
6657
+
6658
+ A namespace is an optionally-named entity whose scope can contain
6659
+ declarations of any kind of entity. The name of a namespace can be used
6660
+ to access entities that belong to that namespace; that is, the *members*
6661
+ of the namespace. Unlike other entities, the definition of a namespace
6662
+ can be split over several parts of one or more translation units and
6663
+ modules.
6664
+
6665
+ [*Note 1*: A *namespace-definition* is exported if it contains any
6666
+ *export-declaration*s [[module.interface]]. A namespace is never
6667
+ attached to a named module and never has a name with module
6668
+ linkage. — *end note*]
6669
+
6670
+ [*Example 1*:
6671
+
6672
+ ``` cpp
6673
+ export module M;
6674
+ namespace N1 {} // N1 is not exported
6675
+ export namespace N2 {} // N2 is exported
6676
+ namespace N3 { export int n; } // N3 is exported
6677
+ ```
6678
+
6679
+ — *end example*]
6680
+
6681
+ There is a *global namespace* with no declaration; see 
6682
+ [[basic.scope.namespace]]. The global namespace belongs to the global
6683
+ scope; it is not an unnamed namespace [[namespace.unnamed]].
6684
+
6685
+ [*Note 2*: Lacking a declaration, it cannot be found by name
6686
+ lookup. — *end note*]
6687
+
6688
+ ### Namespace definition <a id="namespace.def">[[namespace.def]]</a>
6689
+
6690
+ #### General <a id="namespace.def.general">[[namespace.def.general]]</a>
6691
+
6692
+ ``` bnf
6693
+ namespace-name:
6694
+ identifier
6695
+ namespace-alias
6696
+ ```
6697
+
6698
+ ``` bnf
6699
+ namespace-definition:
6700
+ named-namespace-definition
6701
+ unnamed-namespace-definition
6702
+ nested-namespace-definition
6703
+ ```
6704
+
6705
+ ``` bnf
6706
+ named-namespace-definition:
6707
+ inlineₒₚₜ namespace attribute-specifier-seqₒₚₜ identifier '{' namespace-body '}'
6708
+ ```
6709
+
6710
+ ``` bnf
6711
+ unnamed-namespace-definition:
6712
+ inlineₒₚₜ namespace attribute-specifier-seqₒₚₜ '{' namespace-body '}'
6713
+ ```
6714
+
6715
+ ``` bnf
6716
+ nested-namespace-definition:
6717
+ namespace enclosing-namespace-specifier '::' inlineₒₚₜ identifier '{' namespace-body '}'
6718
+ ```
6719
+
6720
+ ``` bnf
6721
+ enclosing-namespace-specifier:
6722
+ identifier
6723
+ enclosing-namespace-specifier '::' inlineₒₚₜ identifier
6724
+ ```
6725
+
6726
+ ``` bnf
6727
+ namespace-body:
6728
+ declaration-seqₒₚₜ
6729
+ ```
6730
+
6731
+ Every *namespace-definition* shall inhabit a namespace scope
6732
+ [[basic.scope.namespace]].
6733
+
6734
+ In a *named-namespace-definition* D, the *identifier* is the name of the
6735
+ namespace. The *identifier* is looked up by searching for it in the
6736
+ scopes of the namespace A in which D appears and of every element of the
6737
+ inline namespace set of A. If the lookup finds a *namespace-definition*
6738
+ for a namespace N, D *extends* N, and the target scope of D is the scope
6739
+ to which N belongs. If the lookup finds nothing, the *identifier* is
6740
+ introduced as a *namespace-name* into A.
6741
+
6742
+ Because a *namespace-definition* contains *declaration*s in its
6743
+ *namespace-body* and a *namespace-definition* is itself a *declaration*,
6744
+ it follows that *namespace-definition*s can be nested.
6745
+
6746
+ [*Example 1*:
6747
+
6748
+ ``` cpp
6749
+ namespace Outer {
6750
+ int i;
6751
+ namespace Inner {
6752
+ void f() { i++; } // Outer::i
6753
+ int i;
6754
+ void g() { i++; } // Inner::i
6755
+ }
6756
+ }
6757
+ ```
6758
+
6759
+ — *end example*]
6760
+
6761
+ If the optional initial `inline` keyword appears in a
6762
+ *namespace-definition* for a particular namespace, that namespace is
6763
+ declared to be an *inline namespace*. The `inline` keyword may be used
6764
+ on a *namespace-definition* that extends a namespace only if it was
6765
+ previously used on the *namespace-definition* that initially declared
6766
+ the *namespace-name* for that namespace.
6767
+
6768
+ The optional *attribute-specifier-seq* in a *named-namespace-definition*
6769
+ appertains to the namespace being defined or extended.
6770
+
6771
+ Members of an inline namespace can be used in most respects as though
6772
+ they were members of the innermost enclosing namespace. Specifically,
6773
+ the inline namespace and its enclosing namespace are both added to the
6774
+ set of associated namespaces used in argument-dependent lookup
6775
+ [[basic.lookup.argdep]] whenever one of them is, and a *using-directive*
6776
+ [[namespace.udir]] that names the inline namespace is implicitly
6777
+ inserted into the enclosing namespace as for an unnamed namespace
6778
+ [[namespace.unnamed]]. Furthermore, each member of the inline namespace
6779
+ can subsequently be partially specialized [[temp.spec.partial]],
6780
+ explicitly instantiated [[temp.explicit]], or explicitly specialized
6781
+ [[temp.expl.spec]] as though it were a member of the enclosing
6782
+ namespace. Finally, looking up a name in the enclosing namespace via
6783
+ explicit qualification [[namespace.qual]] will include members of the
6784
+ inline namespace even if there are declarations of that name in the
6785
+ enclosing namespace.
6786
+
6787
+ These properties are transitive: if a namespace `N` contains an inline
6788
+ namespace `M`, which in turn contains an inline namespace `O`, then the
6789
+ members of `O` can be used as though they were members of `M` or `N`.
6790
+ The *inline namespace set* of `N` is the transitive closure of all
6791
+ inline namespaces in `N`.
6792
+
6793
+ A *nested-namespace-definition* with an *enclosing-namespace-specifier*
6794
+ `E`, *identifier* `I` and *namespace-body* `B` is equivalent to
6795
+
6796
+ ``` cpp
6797
+ namespace E { \opt{inline} namespace I { B } }
6798
+ ```
6799
+
6800
+ where the optional `inline` is present if and only if the *identifier*
6801
+ `I` is preceded by `inline`.
6802
+
6803
+ [*Example 2*:
6804
+
6805
+ ``` cpp
6806
+ namespace A::inline B::C {
6807
+ int i;
6808
+ }
6809
+ ```
6810
+
6811
+ The above has the same effect as:
6812
+
6813
+ ``` cpp
6814
+ namespace A {
6815
+ inline namespace B {
6816
+ namespace C {
6817
+ int i;
6818
+ }
6819
+ }
6820
+ }
6821
+ ```
6822
+
6823
+ — *end example*]
6824
+
6825
+ #### Unnamed namespaces <a id="namespace.unnamed">[[namespace.unnamed]]</a>
6826
+
6827
+ An *unnamed-namespace-definition* behaves as if it were replaced by
6828
+
6829
+ ``` bnf
6830
+ inlineₒₚₜ namespace unique '{' '/* empty body */' '}'
6831
+ using namespace unique ';'
6832
+ namespace unique '{' namespace-body '}'
6833
+ ```
6834
+
6835
+ where `inline` appears if and only if it appears in the
6836
+ *unnamed-namespace-definition* and all occurrences of *`unique`* in a
6837
+ translation unit are replaced by the same identifier, and this
6838
+ identifier differs from all other identifiers in the program. The
6839
+ optional *attribute-specifier-seq* in the *unnamed-namespace-definition*
6840
+ appertains to *`unique`*.
6841
+
6842
+ [*Example 1*:
6843
+
6844
+ ``` cpp
6845
+ namespace { int i; } // unique::i
6846
+ void f() { i++; } // unique::i++
6847
+
6848
+ namespace A {
6849
+ namespace {
6850
+ int i; // A::unique::i
6851
+ int j; // A::unique::j
6852
+ }
6853
+ void g() { i++; } // A::unique::i++
6854
+ }
6855
+
6856
+ using namespace A;
6857
+ void h() {
6858
+ i++; // error: unique::i or A::unique::i
6859
+ A::i++; // A::unique::i
6860
+ j++; // A::unique::j
6861
+ }
6862
+ ```
6863
+
6864
+ — *end example*]
6865
+
6866
+ ### Namespace alias <a id="namespace.alias">[[namespace.alias]]</a>
6867
+
6868
+ A *namespace-alias-definition* declares a *namespace alias* according to
6869
+ the following grammar:
6870
+
6871
+ ``` bnf
6872
+ namespace-alias:
6873
+ identifier
6874
+ ```
6875
+
6876
+ ``` bnf
6877
+ namespace-alias-definition:
6878
+ namespace identifier '=' qualified-namespace-specifier ';'
6879
+ namespace identifier '=' splice-specifier ';'
6880
+ ```
6881
+
6882
+ ``` bnf
6883
+ qualified-namespace-specifier:
6884
+ nested-name-specifierₒₚₜ namespace-name
6885
+ ```
6886
+
6887
+ The *splice-specifier* (if any) shall designate a namespace that is not
6888
+ the global namespace.
6889
+
6890
+ The *identifier* in a *namespace-alias-definition* becomes a
6891
+ *namespace-alias*.
6892
+
6893
+ The underlying entity [[basic.pre]] of the namespace alias is the
6894
+ namespace either denoted by the *qualified-namespace-specifier* or
6895
+ designated by the *splice-specifier*.
6896
+
6897
+ [*Note 1*: When looking up a *namespace-name* in a
6898
+ *namespace-alias-definition*, only namespace names are considered, see 
6899
+ [[basic.lookup.udir]]. — *end note*]
6900
+
6901
+ ### Using namespace directive <a id="namespace.udir">[[namespace.udir]]</a>
6902
+
6903
+ ``` bnf
6904
+ using-directive:
6905
+ attribute-specifier-seqₒₚₜ using namespace nested-name-specifierₒₚₜ namespace-name ';'
6906
+ attribute-specifier-seqₒₚₜ using namespace splice-specifier ';'
6907
+ ```
6908
+
6909
+ The *splice-specifier* (if any) shall designate a namespace that is not
6910
+ the global namespace. The *nested-name-specifier*, *namespace-name*, and
6911
+ *splice-specifier* shall not be dependent.
6912
+
6913
+ A *using-directive* shall not appear in class scope, but may appear in
6914
+ namespace scope or in block scope.
6915
+
6916
+ [*Note 1*: When looking up a *namespace-name* in a *using-directive*,
6917
+ only namespace names are considered, see 
6918
+ [[basic.lookup.udir]]. — *end note*]
6919
+
6920
+ The optional *attribute-specifier-seq* appertains to the
6921
+ *using-directive*.
6922
+
6923
+ [*Note 2*: A *using-directive* makes the names in the designated
6924
+ namespace usable in the scope in which the *using-directive* appears
6925
+ after the *using-directive* [[basic.lookup.unqual]], [[namespace.qual]].
6926
+ During unqualified name lookup, the names appear as if they were
6927
+ declared in the nearest enclosing namespace which contains both the
6928
+ *using-directive* and the designated namespace. — *end note*]
6929
+
6930
+ [*Note 3*: A *using-directive* does not introduce any
6931
+ names. — *end note*]
6932
+
6933
+ [*Example 1*:
6934
+
6935
+ ``` cpp
6936
+ namespace A {
6937
+ int i;
6938
+ namespace B {
6939
+ namespace C {
6940
+ int i;
6941
+ }
6942
+ using namespace A::B::C;
6943
+ void f1() {
6944
+ i = 5; // OK, C::i visible in B and hides A::i
6945
+ }
6946
+ }
6947
+ namespace D {
6948
+ using namespace B;
6949
+ using namespace C;
6950
+ void f2() {
6951
+ i = 5; // ambiguous, B::C::i or A::i?
6952
+ }
6953
+ }
6954
+ void f3() {
6955
+ i = 5; // uses A::i
6956
+ }
6957
+ }
6958
+ void f4() {
6959
+ i = 5; // error: neither i is visible
6960
+ }
6961
+ ```
6962
+
6963
+ — *end example*]
6964
+
6965
+ [*Note 4*: A *using-directive* is transitive: if a scope contains a
6966
+ *using-directive* that designates a namespace that itself contains
6967
+ *using-directive*s, the namespaces designated by those
6968
+ *using-directive*s are also eligible to be considered. — *end note*]
6969
+
6970
+ [*Example 2*:
6971
+
6972
+ ``` cpp
6973
+ namespace M {
6974
+ int i;
6975
+ }
6976
+
6977
+ namespace N {
6978
+ int i;
6979
+ using namespace M;
6980
+ }
6981
+
6982
+ void f() {
6983
+ using namespace N;
6984
+ i = 7; // error: both M::i and N::i are visible
6985
+ }
6986
+ ```
6987
+
6988
+ For another example,
6989
+
6990
+ ``` cpp
6991
+ namespace A {
6992
+ int i;
6993
+ }
6994
+ namespace B {
6995
+ int i;
6996
+ int j;
6997
+ namespace C {
6998
+ namespace D {
6999
+ using namespace A;
7000
+ int j;
7001
+ int k;
7002
+ int a = i; // B::i hides A::i
7003
+ }
7004
+ using namespace D;
7005
+ int k = 89; // no problem yet
7006
+ int l = k; // ambiguous: C::k or D::k
7007
+ int m = i; // B::i hides A::i
7008
+ int n = j; // D::j hides B::j
7009
+ }
7010
+ }
7011
+ ```
7012
+
7013
+ — *end example*]
7014
+
7015
+ [*Note 5*: Declarations in a namespace that appear after a
7016
+ *using-directive* for that namespace can be found through that
7017
+ *using-directive* after they appear. — *end note*]
7018
+
7019
+ [*Note 6*:
7020
+
7021
+ If name lookup finds a declaration for a name in two different
7022
+ namespaces, and the declarations do not declare the same entity and do
7023
+ not declare functions or function templates, the use of the name is
7024
+ ill-formed [[basic.lookup]]. In particular, the name of a variable,
7025
+ function or enumerator does not hide the name of a class or enumeration
7026
+ declared in a different namespace. For example,
7027
+
7028
+ ``` cpp
7029
+ namespace A {
7030
+ class X { };
7031
+ extern "C" int g();
7032
+ extern "C++" int h();
7033
+ }
7034
+ namespace B {
7035
+ void X(int);
7036
+ extern "C" int g();
7037
+ extern "C++" int h(int);
7038
+ }
7039
+ using namespace A;
7040
+ using namespace B;
7041
+
7042
+ void f() {
7043
+ X(1); // error: name X found in two namespaces
7044
+ g(); // OK, name g refers to the same entity
7045
+ h(); // OK, overload resolution selects A::h
7046
+ }
7047
+ ```
7048
+
7049
+ — *end note*]
7050
+
7051
+ [*Note 7*:
7052
+
7053
+ The order in which namespaces are considered and the relationships among
7054
+ the namespaces implied by the *using-directive*s do not affect overload
7055
+ resolution. Neither is any function excluded because another has the
7056
+ same signature, even if one is in a namespace reachable through
7057
+ *using-directive*s in the namespace of the other.[^10]
7058
+
7059
+ — *end note*]
7060
+
7061
+ [*Example 3*:
7062
+
7063
+ ``` cpp
7064
+ namespace D {
7065
+ int d1;
7066
+ void f(char);
7067
+ }
7068
+ using namespace D;
7069
+
7070
+ int d1; // OK, no conflict with D::d1
7071
+
7072
+ namespace E {
7073
+ int e;
7074
+ void f(int);
7075
+ }
7076
+
7077
+ namespace D { // namespace extension
7078
+ int d2;
7079
+ using namespace E;
7080
+ void f(int);
7081
+ }
7082
+
7083
+ void f() {
7084
+ d1++; // error: ambiguous ::d1 or D::d1?
7085
+ ::d1++; // OK
7086
+ D::d1++; // OK
7087
+ d2++; // OK, D::d2
7088
+ e++; // OK, E::e
7089
+ f(1); // error: ambiguous: D::f(int) or E::f(int)?
7090
+ f('a'); // OK, D::f(char)
7091
+ }
7092
+ ```
7093
+
7094
+ — *end example*]
7095
+
7096
+ ## The `using` declaration <a id="namespace.udecl">[[namespace.udecl]]</a>
7097
+
7098
+ ``` bnf
7099
+ using-declaration:
7100
+ using using-declarator-list ';'
7101
+ ```
7102
+
7103
+ ``` bnf
7104
+ using-declarator-list:
7105
+ using-declarator '...'ₒₚₜ
7106
+ using-declarator-list ',' using-declarator '...'ₒₚₜ
7107
+ ```
7108
+
7109
+ ``` bnf
7110
+ using-declarator:
7111
+ typenameₒₚₜ nested-name-specifier unqualified-id
7112
+ ```
7113
+
7114
+ The component names of a *using-declarator* are those of its
7115
+ *nested-name-specifier* and *unqualified-id*. Each *using-declarator* in
7116
+ a *using-declaration*[^11]
7117
+
7118
+ names the set of declarations found by lookup [[basic.lookup.qual]] for
7119
+ the *using-declarator*, except that class and enumeration declarations
7120
+ that would be discarded are merely ignored when checking for ambiguity
7121
+ [[basic.lookup]], conversion function templates with a dependent return
7122
+ type are ignored, and certain functions are hidden as described below.
7123
+ If the terminal name of the *using-declarator* is dependent
7124
+ [[temp.dep.type]], the *using-declarator* is considered to name a
7125
+ constructor if and only if the *nested-name-specifier* has a terminal
7126
+ name that is the same as the *unqualified-id*. If the lookup in any
7127
+ instantiation finds that a *using-declarator* that is not considered to
7128
+ name a constructor does do so, or that a *using-declarator* that is
7129
+ considered to name a constructor does not, the program is ill-formed.
7130
+
7131
+ If the *using-declarator* names a constructor, it declares that the
7132
+ class *inherits* the named set of constructor declarations from the
7133
+ nominated base class.
7134
+
7135
+ [*Note 1*: Otherwise, the *unqualified-id* in the *using-declarator* is
7136
+ bound to the *using-declarator*, which is replaced during name lookup
7137
+ with the declarations it names [[basic.lookup]]. If such a declaration
7138
+ is of an enumeration, the names of its enumerators are not bound. For
7139
+ the keyword `typename`, see [[temp.res]]. — *end note*]
7140
+
7141
+ In a *using-declaration* used as a *member-declaration*, each
7142
+ *using-declarator* shall either name an enumerator or have a
7143
+ *nested-name-specifier* naming a base class of the current class
7144
+ [[expr.prim.this]].
7145
+
7146
+ [*Example 1*:
7147
+
7148
+ ``` cpp
7149
+ enum class button { up, down };
7150
+ struct S {
7151
+ using button::up;
7152
+ button b = up; // OK
7153
+ };
7154
+ ```
7155
+
7156
+ — *end example*]
7157
+
7158
+ If a *using-declarator* names a constructor, its *nested-name-specifier*
7159
+ shall name a direct base class of the current class. If the immediate
7160
+ (class) scope is associated with a class template, it shall derive from
7161
+ the specified base class or have at least one dependent base class.
7162
+
7163
+ [*Example 2*:
7164
+
7165
+ ``` cpp
7166
+ struct B {
7167
+ void f(char);
7168
+ enum E { e };
7169
+ union { int x; };
7170
+ };
7171
+
7172
+ struct C {
7173
+ int f();
7174
+ };
7175
+
7176
+ struct D : B {
7177
+ using B::f; // OK, B is a base of D
7178
+ using B::e; // OK, e is an enumerator of base B
7179
+ using B::x; // OK, x is a union member of base B
7180
+ using C::f; // error: C isn't a base of D
7181
+ void f(int) { f('c'); } // calls B::f(char)
7182
+ void g(int) { g('c'); } // recursively calls D::g(int)
7183
+ };
7184
+ template <typename... bases>
7185
+ struct X : bases... {
7186
+ using bases::f...;
7187
+ };
7188
+ X<B, C> x; // OK, B::f and C::f named
7189
+ ```
7190
+
7191
+ — *end example*]
7192
+
7193
+ [*Note 2*: Since destructors do not have names, a *using-declaration*
7194
+ cannot refer to a destructor for a base class. — *end note*]
7195
+
7196
+ If a constructor or assignment operator brought from a base class into a
7197
+ derived class has the signature of a copy/move constructor or assignment
7198
+ operator for the derived class
7199
+ [[class.copy.ctor]], [[class.copy.assign]], the *using-declaration* does
7200
+ not by itself suppress the implicit declaration of the derived class
7201
+ member; the member from the base class is hidden or overridden by the
7202
+ implicitly-declared copy/move constructor or assignment operator of the
7203
+ derived class, as described below.
7204
+
7205
+ A *using-declaration* shall not name a *template-id*.
7206
+
7207
+ [*Example 3*:
7208
+
7209
+ ``` cpp
7210
+ struct A {
7211
+ template <class T> void f(T);
7212
+ template <class T> struct X { };
7213
+ };
7214
+ struct B : A {
7215
+ using A::f<double>; // error
7216
+ using A::X<int>; // error
7217
+ };
7218
+ ```
7219
+
7220
+ — *end example*]
7221
+
7222
+ A *using-declaration* shall not name a namespace.
7223
+
7224
+ A *using-declaration* that names a class member other than an enumerator
7225
+ shall be a *member-declaration*.
7226
+
7227
+ [*Example 4*:
7228
+
7229
+ ``` cpp
7230
+ struct X {
7231
+ int i;
7232
+ static int s;
7233
+ };
7234
+
7235
+ void f() {
7236
+ using X::i; // error: X::i is a class member and this is not a member declaration.
7237
+ using X::s; // error: X::s is a class member and this is not a member declaration.
7238
+ }
7239
+ ```
7240
+
7241
+ — *end example*]
7242
+
7243
+ If a declaration is named by two *using-declarator*s that inhabit the
7244
+ same class scope, the program is ill-formed.
7245
+
7246
+ [*Example 5*:
7247
+
7248
+ ``` cpp
7249
+ struct C {
7250
+ int i;
7251
+ };
7252
+
7253
+ struct D1 : C { };
7254
+ struct D2 : C { };
7255
+
7256
+ struct D3 : D1, D2 {
7257
+ using D1::i; // OK, equivalent to using C::i
7258
+ using D1::i; // error: duplicate
7259
+ using D2::i; // error: duplicate, also names C::i
7260
+ };
7261
+ ```
7262
+
7263
+ — *end example*]
7264
+
7265
+ [*Note 3*: A *using-declarator* whose *nested-name-specifier* names a
7266
+ namespace does not name declarations added to the namespace after it.
7267
+ Thus, additional overloads added after the *using-declaration* are
7268
+ ignored, but default function arguments [[dcl.fct.default]], default
7269
+ template arguments [[temp.param]], and template specializations
7270
+ [[temp.spec.partial]], [[temp.expl.spec]] are considered. — *end note*]
7271
+
7272
+ [*Example 6*:
7273
+
7274
+ ``` cpp
7275
+ namespace A {
7276
+ void f(int);
7277
+ }
7278
+
7279
+ using A::f; // f is a synonym for A::f; that is, for A::f(int).
7280
+ namespace A {
7281
+ void f(char);
7282
+ }
7283
+
7284
+ void foo() {
7285
+ f('a'); // calls f(int), even though f(char) exists.
7286
+ }
7287
+
7288
+ void bar() {
7289
+ using A::f; // f is a synonym for A::f; that is, for A::f(int) and A::f(char).
7290
+ f('a'); // calls f(char)
7291
+ }
7292
+ ```
7293
+
7294
+ — *end example*]
7295
+
7296
+ If a declaration named by a *using-declaration* that inhabits the target
7297
+ scope of another declaration B potentially conflicts with it
7298
+ [[basic.scope.scope]], and either is reachable from the other, the
7299
+ program is ill-formed unless B is name-independent and the
7300
+ *using-declaration* precedes B.
7301
+
7302
+ [*Example 7*:
7303
+
7304
+ ``` cpp
7305
+ int _;
7306
+ void f() {
7307
+ int _; // B
7308
+ _ = 0;
7309
+ using ::_; // error: using-declaration does not precede B
7310
+ }
7311
+ ```
7312
+
7313
+ — *end example*]
7314
+
7315
+ If two declarations named by *using-declaration*s that inhabit the same
7316
+ scope potentially conflict, either is reachable from the other, and they
7317
+ do not both declare functions or function templates, the program is
7318
+ ill-formed.
7319
+
7320
+ [*Note 4*: Overload resolution possibly cannot distinguish between
7321
+ conflicting function declarations. — *end note*]
7322
+
7323
+ [*Example 8*:
7324
+
7325
+ ``` cpp
7326
+ namespace A {
7327
+ int x;
7328
+ int f(int);
7329
+ int g;
7330
+ void h();
7331
+ }
7332
+
7333
+ namespace B {
7334
+ int i;
7335
+ struct g { };
7336
+ struct x { };
7337
+ void f(int);
7338
+ void f(double);
7339
+ void g(char); // OK, hides struct g
7340
+ }
7341
+
7342
+ void func() {
7343
+ int i;
7344
+ using B::i; // error: conflicts
7345
+ void f(char);
7346
+ using B::f; // OK, each f is a function
7347
+ using A::f; // OK, but interferes with B::f(int)
7348
+ f(1); // error: ambiguous
7349
+ static_cast<int(*)(int)>(f)(1); // OK, calls A::f
7350
+ f(3.5); // calls B::f(double)
7351
+ using B::g;
7352
+ g('a'); // calls B::g(char)
7353
+ struct g g1; // g1 has class type B::g
7354
+ using A::g; // error: conflicts with B::g
7355
+ void h();
7356
+ using A::h; // error: conflicts
7357
+ using B::x;
7358
+ using A::x; // OK, hides struct B::x
7359
+ using A::x; // OK, does not conflict with previous using A::x
7360
+ x = 99; // assigns to A::x
7361
+ struct x x1; // x1 has class type B::x
7362
+ }
7363
+ ```
7364
+
7365
+ — *end example*]
7366
+
7367
+ The set of declarations named by a *using-declarator* that inhabits a
7368
+ class `C` does not include member functions and member function
7369
+ templates of a base class that correspond to (and thus would conflict
7370
+ with) a declaration of a function or function template in `C`.
7371
+
7372
+ [*Example 9*:
7373
+
7374
+ ``` cpp
7375
+ struct B {
7376
+ virtual void f(int);
7377
+ virtual void f(char);
7378
+ void g(int);
7379
+ void h(int);
7380
+ };
7381
+
7382
+ struct D : B {
7383
+ using B::f;
7384
+ void f(int); // OK, D::f(int) overrides B::f(int);
7385
+
7386
+ using B::g;
7387
+ void g(char); // OK
7388
+
7389
+ using B::h;
7390
+ void h(int); // OK, D::h(int) hides B::h(int)
7391
+ };
7392
+
7393
+ void k(D* p)
7394
+ {
7395
+ p->f(1); // calls D::f(int)
7396
+ p->f('a'); // calls B::f(char)
7397
+ p->g(1); // calls B::g(int)
7398
+ p->g('a'); // calls D::g(char)
7399
+ }
7400
+
7401
+ struct B1 {
7402
+ B1(int);
7403
+ };
7404
+
7405
+ struct B2 {
7406
+ B2(int);
7407
+ };
7408
+
7409
+ struct D1 : B1, B2 {
7410
+ using B1::B1;
7411
+ using B2::B2;
7412
+ };
7413
+ D1 d1(0); // error: ambiguous
7414
+
7415
+ struct D2 : B1, B2 {
7416
+ using B1::B1;
7417
+ using B2::B2;
7418
+ D2(int); // OK, D2::D2(int) hides B1::B1(int) and B2::B2(int)
7419
+ };
7420
+ D2 d2(0); // calls D2::D2(int)
7421
+ ```
7422
+
7423
+ — *end example*]
7424
+
7425
+ [*Note 5*: For the purpose of forming a set of candidates during
7426
+ overload resolution, the functions named by a *using-declaration* in a
7427
+ derived class are treated as though they were direct members of the
7428
+ derived class. In particular, the implicit object parameter is treated
7429
+ as if it were a reference to the derived class rather than to the base
7430
+ class [[over.match.funcs]]. This has no effect on the type of the
7431
+ function, and in all other respects the function remains part of the
7432
+ base class. — *end note*]
7433
+
7434
+ Constructors that are named by a *using-declaration* are treated as
7435
+ though they were constructors of the derived class when looking up the
7436
+ constructors of the derived class [[class.qual]] or forming a set of
7437
+ overload candidates
7438
+ [[over.match.ctor]], [[over.match.copy]], [[over.match.list]].
7439
+
7440
+ [*Note 6*: If such a constructor is selected to perform the
7441
+ initialization of an object of class type, all subobjects other than the
7442
+ base class from which the constructor originated are implicitly
7443
+ initialized [[class.inhctor.init]]. A constructor of a derived class is
7444
+ sometimes preferred to a constructor of a base class if they would
7445
+ otherwise be ambiguous [[over.match.best]]. — *end note*]
7446
+
7447
+ In a *using-declarator* that does not name a constructor, every
7448
+ declaration named shall be accessible. In a *using-declarator* that
7449
+ names a constructor, no access check is performed.
7450
+
7451
+ [*Note 7*:
7452
+
7453
+ Because a *using-declarator* designates a base class member (and not a
7454
+ member subobject or a member function of a base class subobject), a
7455
+ *using-declarator* cannot be used to resolve inherited member
7456
+ ambiguities.
7457
+
7458
+ [*Example 10*:
7459
+
7460
+ ``` cpp
7461
+ struct A { int x(); };
7462
+ struct B : A { };
7463
+ struct C : A {
7464
+ using A::x;
7465
+ int x(int);
7466
+ };
7467
+
7468
+ struct D : B, C {
7469
+ using C::x;
7470
+ int x(double);
7471
+ };
7472
+ int f(D* d) {
7473
+ return d->x(); // error: overload resolution selects A::x, but A is an ambiguous base class
7474
+ }
7475
+ ```
7476
+
7477
+ — *end example*]
7478
+
7479
+ — *end note*]
7480
+
7481
+ A *using-declaration* has the usual accessibility for a
7482
+ *member-declaration*. Base-class constructors considered because of a
7483
+ *using-declarator* are accessible if they would be accessible when used
7484
+ to construct an object of the base class; the accessibility of the
7485
+ *using-declaration* is ignored.
7486
+
7487
+ [*Example 11*:
7488
+
7489
+ ``` cpp
7490
+ class A {
7491
+ private:
7492
+ void f(char);
7493
+ public:
7494
+ void f(int);
7495
+ protected:
7496
+ void g();
7497
+ };
7498
+
7499
+ class B : public A {
7500
+ using A::f; // error: A::f(char) is inaccessible
7501
+ public:
7502
+ using A::g; // B::g is a public synonym for A::g
7503
+ };
7504
+ ```
7505
+
7506
+ — *end example*]
7507
+
7508
+ ## The `asm` declaration <a id="dcl.asm">[[dcl.asm]]</a>
7509
+
7510
+ An `asm` declaration has the form
7511
+
7512
+ ``` bnf
7513
+ asm-declaration:
7514
+ attribute-specifier-seqₒₚₜ asm '(' balanced-token-seq ')' ';'
7515
+ ```
7516
+
7517
+ The `asm` declaration is conditionally-supported; any restrictions on
7518
+ the *balanced-token-seq* and its meaning are *implementation-defined*.
7519
+ The optional *attribute-specifier-seq* in an *asm-declaration*
7520
+ appertains to the `asm` declaration.
7521
+
7522
+ [*Note 1*: Typically it is used to pass information through the
7523
+ implementation to an assembler. — *end note*]
7524
+
7525
+ ## Linkage specifications <a id="dcl.link">[[dcl.link]]</a>
7526
+
7527
+ All functions and variables whose names have external linkage and all
7528
+ function types have a *language linkage*.
7529
+
7530
+ [*Note 1*: Some of the properties associated with an entity with
7531
+ language linkage are specific to each implementation and are not
7532
+ described here. For example, a particular language linkage might be
7533
+ associated with a particular form of representing names of objects and
7534
+ functions with external linkage, or with a particular calling
7535
+ convention, etc. — *end note*]
7536
+
7537
+ The default language linkage of all function types, functions, and
7538
+ variables is C++ language linkage. Two function types with different
7539
+ language linkages are distinct types even if they are otherwise
7540
+ identical.
7541
+
7542
+ Linkage [[basic.link]] between C++ and non-C++ code fragments can be
7543
+ achieved using a *linkage-specification*:
7544
+
7545
+ ``` bnf
7546
+ linkage-specification:
7547
+ extern unevaluated-string '{' declaration-seqₒₚₜ '}'
7548
+ extern unevaluated-string name-declaration
7549
+ ```
7550
+
7551
+ The *unevaluated-string* indicates the required language linkage.
7552
+
7553
+ [*Note 2*: Escape sequences and *universal-character-name*s have been
7554
+ replaced [[lex.string.uneval]]. — *end note*]
7555
+
7556
+ This document specifies the semantics for the *unevaluated-string*s
7557
+ `"C"` and `"C++"`. Use of an *unevaluated-string* other than `"C"` or
7558
+ `"C++"` is conditionally-supported, with *implementation-defined*
7559
+ semantics.
7560
+
7561
+ [*Note 3*: Therefore, a *linkage-specification* with a language linkage
7562
+ that is unknown to the implementation requires a
7563
+ diagnostic. — *end note*]
7564
+
7565
+ *Recommended practice:* The spelling of the language linkage should be
7566
+ taken from the document defining that language. For example, `Ada` (not
7567
+ `ADA`) and `Fortran` or `FORTRAN`, depending on the vintage.
7568
+
7569
+ Every implementation shall provide for linkage to the C programming
7570
+ language, `"C"`, and C++, `"C++"`.
7571
+
7572
+ [*Example 1*:
7573
+
7574
+ ``` cpp
7575
+ complex sqrt(complex); // C++{} language linkage by default
7576
+ extern "C" {
7577
+ double sqrt(double); // C language linkage
7578
+ }
7579
+ ```
7580
+
7581
+ — *end example*]
7582
+
7583
+ A *module-import-declaration* appearing in a linkage specification with
7584
+ other than C++ language linkage is conditionally-supported with
7585
+ *implementation-defined* semantics.
7586
+
7587
+ Linkage specifications nest. When linkage specifications nest, the
7588
+ innermost one determines the language linkage.
7589
+
7590
+ [*Note 4*: A linkage specification does not establish a
7591
+ scope. — *end note*]
7592
+
7593
+ A *linkage-specification* shall inhabit a namespace scope. In a
7594
+ *linkage-specification*, the specified language linkage applies to the
7595
+ function types of all function declarators and to all functions and
7596
+ variables whose names have external linkage.
7597
+
7598
+ [*Example 2*:
7599
+
7600
+ ``` cpp
7601
+ extern "C" // f1 and its function type have C language linkage;
7602
+ void f1(void(*pf)(int)); // pf is a pointer to a C function
7603
+
7604
+ extern "C" typedef void FUNC();
7605
+ FUNC f2; // f2 has C++{} language linkage and
7606
+ // its type has C language linkage
7607
+
7608
+ extern "C" FUNC f3; // f3 and its type have C language linkage
7609
+
7610
+ void (*pf2)(FUNC*); // the variable pf2 has C++{} language linkage; its type
7611
+ // is ``pointer to C++{} function that takes one parameter of type
7612
+ // pointer to C function''
7613
+ extern "C" {
7614
+ static void f4(); // the name of the function f4 has internal linkage,
7615
+ // so f4 has no language linkage; its type has C language linkage
7616
+ }
7617
+
7618
+ extern "C" void f5() {
7619
+ extern void f4(); // OK, name linkage (internal) and function type linkage (C language linkage)
7620
+ // obtained from previous declaration.
7621
+ }
7622
+
7623
+ extern void f4(); // OK, name linkage (internal) and function type linkage (C language linkage)
7624
+ // obtained from previous declaration.
7625
+
7626
+ void f6() {
7627
+ extern void f4(); // OK, name linkage (internal) and function type linkage (C language linkage)
7628
+ // obtained from previous declaration.
7629
+ }
7630
+ ```
7631
+
7632
+ — *end example*]
7633
+
7634
+ A C language linkage is ignored in determining the language linkage of
7635
+ class members, friend functions with a trailing *requires-clause*, and
7636
+ the function type of non-static class member functions.
7637
+
7638
+ [*Example 3*:
7639
+
7640
+ ``` cpp
7641
+ extern "C" typedef void FUNC_c();
7642
+
7643
+ class C {
7644
+ void mf1(FUNC_c*); // the function mf1 and its type have C++{} language linkage;
7645
+ // the parameter has type ``pointer to C function''
7646
+
7647
+ FUNC_c mf2; // the function mf2 and its type have C++{} language linkage
7648
+
7649
+ static FUNC_c* q; // the data member q has C++{} language linkage;
7650
+ // its type is ``pointer to C function''
7651
+ };
7652
+
7653
+ extern "C" {
7654
+ class X {
7655
+ void mf(); // the function mf and its type have C++{} language linkage
7656
+ void mf2(void(*)()); // the function mf2 has C++{} language linkage;
7657
+ // the parameter has type ``pointer to C function''
7658
+ };
7659
+ }
7660
+ ```
7661
+
7662
+ — *end example*]
7663
+
7664
+ If two declarations of an entity give it different language linkages,
7665
+ the program is ill-formed; no diagnostic is required if neither
7666
+ declaration is reachable from the other. A redeclaration of an entity
7667
+ without a linkage specification inherits the language linkage of the
7668
+ entity and (if applicable) its type.
7669
+
7670
+ Two declarations declare the same entity if they (re)introduce the same
7671
+ name, one declares a function or variable with C language linkage, and
7672
+ the other declares such an entity or declares a variable that belongs to
7673
+ the global scope.
7674
+
7675
+ [*Example 4*:
7676
+
7677
+ ``` cpp
7678
+ int x;
7679
+ namespace A {
7680
+ extern "C" int f();
7681
+ extern "C" int g() { return 1; }
7682
+ extern "C" int h();
7683
+ extern "C" int x(); // error: same name as global-space object x
7684
+ }
7685
+
7686
+ namespace B {
7687
+ extern "C" int f(); // A::f and B::f refer to the same function
7688
+ extern "C" int g() { return 1; } // error: the function g with C language linkage has two definitions
7689
+ }
7690
+
7691
+ int A::f() { return 98; } // definition for the function f with C language linkage
7692
+ extern "C" int h() { return 97; } // definition for the function h with C language linkage
7693
+ // A::h and ::h refer to the same function
7694
+ ```
7695
+
7696
+ — *end example*]
7697
+
7698
+ A declaration directly contained in a *linkage-specification* is treated
7699
+ as if it contains the `extern` specifier [[dcl.stc]] for the purpose of
7700
+ determining the linkage of the declared name and whether it is a
7701
+ definition. Such a declaration shall not have a
7702
+ *storage-class-specifier*.
7703
+
7704
+ [*Example 5*:
7705
+
7706
+ ``` cpp
7707
+ extern "C" double f();
7708
+ static double f(); // error
7709
+ extern "C" int i; // declaration
7710
+ extern "C" {
7711
+ int i; // definition
7712
+ }
7713
+ extern "C" static void g(); // error
7714
+ ```
7715
+
7716
+ — *end example*]
7717
+
7718
+ [*Note 5*: Because the language linkage is part of a function type,
7719
+ when indirecting through a pointer to C function, the function to which
7720
+ the resulting lvalue refers is considered a C function. — *end note*]
7721
+
7722
+ Linkage from C++ to entities defined in other languages and to entities
7723
+ defined in C++ from other languages is *implementation-defined* and
7724
+ language-dependent. Only where the object layout strategies of two
7725
+ language implementations are similar enough can such linkage be
7726
+ achieved.
7727
+
7728
+ ## Attributes <a id="dcl.attr">[[dcl.attr]]</a>
7729
+
7730
+ ### Attribute syntax and semantics <a id="dcl.attr.grammar">[[dcl.attr.grammar]]</a>
7731
+
7732
+ Attributes and annotations specify additional information for various
7733
+ source constructs such as types, variables, names, contract assertions,
7734
+ blocks, or translation units.
7735
+
7736
+ ``` bnf
7737
+ attribute-specifier-seq:
7738
+ attribute-specifier attribute-specifier-seqₒₚₜ
7739
+ ```
7740
+
7741
+ ``` bnf
7742
+ attribute-specifier:
7743
+ '[' '[' attribute-using-prefixₒₚₜ attribute-list ']' ']'
7744
+ '[' '[' annotation-list ']' ']'
7745
+ alignment-specifier
7746
+ ```
7747
+
7748
+ ``` bnf
7749
+ alignment-specifier:
7750
+ alignas '(' type-id '...'ₒₚₜ ')'
7751
+ alignas '(' constant-expression '...'ₒₚₜ ')'
7752
+ ```
7753
+
7754
+ ``` bnf
7755
+ attribute-using-prefix:
7756
+ using attribute-namespace ':'
7757
+ ```
7758
+
7759
+ ``` bnf
7760
+ attribute-list:
7761
+ attributeₒₚₜ
7762
+ attribute-list ',' attributeₒₚₜ
7763
+ attribute '...'
7764
+ attribute-list ',' attribute '...'
7765
+ ```
7766
+
7767
+ ``` bnf
7768
+ annotation-list:
7769
+ annotation '...'ₒₚₜ
7770
+ annotation-list ',' annotation '...'ₒₚₜ
7771
+ ```
7772
+
7773
+ ``` bnf
7774
+ attribute:
7775
+ attribute-token attribute-argument-clauseₒₚₜ
7776
+ ```
7777
+
7778
+ ``` bnf
7779
+ annotation:
7780
+ '=' constant-expression
7781
+ ```
7782
+
7783
+ ``` bnf
7784
+ attribute-token:
7785
+ identifier
7786
+ attribute-scoped-token
7787
+ ```
7788
+
7789
+ ``` bnf
7790
+ attribute-scoped-token:
7791
+ attribute-namespace '::' identifier
7792
+ ```
7793
+
7794
+ ``` bnf
7795
+ attribute-namespace:
7796
+ identifier
7797
+ ```
7798
+
7799
+ ``` bnf
7800
+ attribute-argument-clause:
7801
+ '(' balanced-token-seqₒₚₜ ')'
7802
+ ```
7803
+
7804
+ ``` bnf
7805
+ balanced-token-seq:
7806
+ balanced-token balanced-token-seqₒₚₜ
7807
+ ```
7808
+
7809
+ ``` bnf
7810
+ balanced-token:
7811
+ '(' balanced-token-seqₒₚₜ ')'
7812
+ '[' balanced-token-seqₒₚₜ ']'
7813
+ '{' balanced-token-seqₒₚₜ '}'
7814
+ '[:' balanced-token-seqₒₚₜ ':]'
7815
+ any *token* other than '(', ')', '[', ']', '{', '}', '[:', or ':]'
7816
+ ```
7817
+
7818
+ If an *attribute-specifier* contains an *attribute-using-prefix*, the
7819
+ *attribute-list* following that *attribute-using-prefix* shall not
7820
+ contain an *attribute-scoped-token* and every *attribute-token* in that
7821
+ *attribute-list* is treated as if its *identifier* were prefixed with
7822
+ `N::`, where `N` is the *attribute-namespace* specified in the
7823
+ *attribute-using-prefix*.
7824
+
7825
+ [*Note 1*: This rule imposes no constraints on how an
7826
+ *attribute-using-prefix* affects the tokens in an
7827
+ *attribute-argument-clause*. — *end note*]
7828
+
7829
+ [*Example 1*:
7830
+
7831
+ ``` cpp
7832
+ [[using CC: opt(1), debug]] // same as [[CC::opt(1), CC::debug]]
7833
+ void f() {}
7834
+ [[using CC: opt(1)]] [[CC::debug]] // same as [[CC::opt(1)]] [[CC::debug]]
7835
+ void g() {}
7836
+ [[using CC: CC::opt(1)]] // error: cannot combine using and scoped attribute token
7837
+ void h() {}
7838
+ ```
7839
+
7840
+ — *end example*]
7841
+
7842
+ [*Note 2*: For each individual attribute, the form of the
7843
+ *balanced-token-seq* will be specified. — *end note*]
7844
+
7845
+ In an *attribute-list*, an ellipsis may appear only if that
7846
+ *attribute*’s specification permits it. An *attribute* followed by an
7847
+ ellipsis is a pack expansion [[temp.variadic]]. An *attribute-specifier*
7848
+ that contains an *attribute-list* with no *attribute*s has no effect.
7849
+ The order in which the *attribute-token*s appear in an *attribute-list*
7850
+ is not significant. If a keyword [[lex.key]] or an alternative token
7851
+ [[lex.digraph]] that satisfies the syntactic requirements of an
7852
+ *identifier* [[lex.name]] is contained in an *attribute-token*, it is
7853
+ considered an identifier. No name lookup [[basic.lookup]] is performed
7854
+ on any of the identifiers contained in an *attribute-token*. The
7855
+ *attribute-token* determines additional requirements on the
7856
+ *attribute-argument-clause* (if any).
7857
+
7858
+ An *annotation* followed by an ellipsis is a pack expansion
7859
+ [[temp.variadic]].
7860
+
7861
+ Each *attribute-specifier-seq* is said to *appertain* to some entity or
7862
+ statement, identified by the syntactic context where it appears
7863
+ [[stmt]], [[dcl]], [[dcl.decl]]. If an *attribute-specifier-seq* that
7864
+ appertains to some entity or statement contains an *attribute* or
7865
+ *alignment-specifier* that is not allowed to apply to that entity or
7866
+ statement, the program is ill-formed. If an *attribute-specifier-seq*
7867
+ appertains to a friend declaration [[class.friend]], that declaration
7868
+ shall be a definition.
7869
+
7870
+ [*Note 3*: An *attribute-specifier-seq* cannot appertain to an explicit
7871
+ instantiation [[temp.explicit]]. — *end note*]
7872
+
7873
+ For an *attribute-token* (including an *attribute-scoped-token*) not
7874
+ specified in this document, the behavior is *implementation-defined*;
7875
+ any such *attribute-token* that is not recognized by the implementation
7876
+ is ignored.
7877
+
7878
+ [*Note 4*: A program is ill-formed if it contains an *attribute*
7879
+ specified in [[dcl.attr]] that violates the rules specifying to which
7880
+ entity or statement the attribute can apply or the syntax rules for the
7881
+ attribute’s *attribute-argument-clause*, if any. — *end note*]
7882
+
7883
+ [*Note 5*: The *attribute*s specified in [[dcl.attr]] have optional
7884
+ semantics: given a well-formed program, removing all instances of any
7885
+ one of those *attribute*s results in a program whose set of possible
7886
+ executions [[intro.abstract]] for a given input is a subset of those of
7887
+ the original program for the same input, absent implementation-defined
7888
+ guarantees with respect to that *attribute*. — *end note*]
7889
+
7890
+ An *attribute-token* is reserved for future standardization if
7891
+
7892
+ - it is not an *attribute-scoped-token* and is not specified in this
7893
+ document, or
7894
+ - it is an *attribute-scoped-token* and its *attribute-namespace* is
7895
+ `std` followed by zero or more digits.
7896
+
7897
+ Each implementation should choose a distinctive name for the
7898
+ *attribute-namespace* in an *attribute-scoped-token*.
7899
+
7900
+ Two consecutive left square bracket tokens shall appear only when
7901
+ introducing an *attribute-specifier* or within the *balanced-token-seq*
7902
+ of an *attribute-argument-clause*.
7903
+
7904
+ [*Note 6*: If two consecutive left square brackets appear where an
7905
+ *attribute-specifier* is not allowed, the program is ill-formed even if
7906
+ the brackets match an alternative grammar production. — *end note*]
7907
+
7908
+ [*Example 2*:
7909
+
7910
+ ``` cpp
7911
+ int p[10];
7912
+ void f() {
7913
+ int x = 42, y[5];
7914
+ int(p[[x] { return x; }()]); // error: invalid attribute on a nested declarator-id and
7915
+ // not a function-style cast of an element of p.
7916
+ y[[] { return 2; }()] = 2; // error even though attributes are not allowed in this context.
7917
+ int i [[vendor::attr([[]])]]; // well-formed implementation-defined attribute.
7918
+ }
7919
+ ```
7920
+
7921
+ — *end example*]
7922
+
7923
+ ### Alignment specifier <a id="dcl.align">[[dcl.align]]</a>
7924
+
7925
+ An *alignment-specifier* may be applied to a variable or to a class data
7926
+ member, but it shall not be applied to a bit-field, a function
7927
+ parameter, or an *exception-declaration* [[except.handle]]. An
7928
+ *alignment-specifier* may also be applied to the declaration of a class
7929
+ (in an *elaborated-type-specifier* [[dcl.type.elab]] or *class-head*
7930
+ [[class]], respectively). An *alignment-specifier* with an ellipsis is a
7931
+ pack expansion [[temp.variadic]].
7932
+
7933
+ When the *alignment-specifier* is of the form `alignas(`
7934
+ *constant-expression* `)`:
7935
+
7936
+ - the *constant-expression* shall be an integral constant expression
7937
+ - if the constant expression does not evaluate to an alignment value
7938
+ [[basic.align]], or evaluates to an extended alignment and the
7939
+ implementation does not support that alignment in the context of the
7940
+ declaration, the program is ill-formed.
7941
+
7942
+ An *alignment-specifier* of the form `alignas(` *type-id* `)` has the
7943
+ same effect as `alignas({}alignof(` *type-id* `))` [[expr.alignof]].
7944
+
7945
+ The alignment requirement of an entity is the strictest nonzero
7946
+ alignment specified by its *alignment-specifier*s, if any; otherwise,
7947
+ the *alignment-specifier*s have no effect.
7948
+
7949
+ The combined effect of all *alignment-specifier*s in a declaration shall
7950
+ not specify an alignment that is less strict than the alignment that
7951
+ would be required for the entity being declared if all
7952
+ *alignment-specifier*s appertaining to that entity were omitted.
7953
+
7954
+ [*Example 1*:
7955
+
7956
+ ``` cpp
7957
+ struct alignas(8) S {};
7958
+ struct alignas(1) U {
7959
+ S s;
7960
+ }; // error: U specifies an alignment that is less strict than if the alignas(1) were omitted.
7961
+ ```
7962
+
7963
+ — *end example*]
7964
+
7965
+ If the defining declaration of an entity has an *alignment-specifier*,
7966
+ any non-defining declaration of that entity shall either specify
7967
+ equivalent alignment or have no *alignment-specifier*. Conversely, if
7968
+ any declaration of an entity has an *alignment-specifier*, every
7969
+ defining declaration of that entity shall specify an equivalent
7970
+ alignment. No diagnostic is required if declarations of an entity have
7971
+ different *alignment-specifier*s in different translation units.
7972
+
7973
+ [*Example 2*:
7974
+
7975
+ ``` cpp
7976
+ // Translation unit #1:
7977
+ struct S { int x; } s, *p = &s;
7978
+
7979
+ // Translation unit #2:
7980
+ struct alignas(16) S; // ill-formed, no diagnostic required: definition of S lacks alignment
7981
+ extern S* p;
7982
+ ```
7983
+
7984
+ — *end example*]
7985
+
7986
+ [*Example 3*:
7987
+
7988
+ An aligned buffer with an alignment requirement of `A` and holding `N`
7989
+ elements of type `T` can be declared as:
7990
+
7991
+ ``` cpp
7992
+ alignas(T) alignas(A) T buffer[N];
7993
+ ```
7994
+
7995
+ Specifying `alignas(T)` ensures that the final requested alignment will
7996
+ not be weaker than `alignof(T)`, and therefore the program will not be
7997
+ ill-formed.
7998
+
7999
+ — *end example*]
8000
+
8001
+ [*Example 4*:
8002
+
8003
+ ``` cpp
8004
+ alignas(double) void f(); // error: alignment applied to function
8005
+ alignas(double) unsigned char c[sizeof(double)]; // array of characters, suitably aligned for a double
8006
+ extern unsigned char c[sizeof(double)]; // no alignas necessary
8007
+ alignas(float)
8008
+ extern unsigned char c[sizeof(double)]; // error: different alignment in declaration
8009
+ ```
8010
+
8011
+ — *end example*]
8012
+
8013
+ ### Assumption attribute <a id="dcl.attr.assume">[[dcl.attr.assume]]</a>
8014
+
8015
+ The *attribute-token* `assume` may be applied to a null statement; such
8016
+ a statement is an *assumption*. An *attribute-argument-clause* shall be
8017
+ present and shall have the form:
8018
+
8019
+ ``` bnf
8020
+ '(' conditional-expression ')'
8021
+ ```
8022
+
8023
+ The expression is contextually converted to `bool` [[conv.general]]. The
8024
+ expression is not evaluated. If the converted expression would evaluate
8025
+ to `true` at the point where the assumption appears, the assumption has
8026
+ no effect. Otherwise, evaluation of the assumption has runtime-undefined
8027
+ behavior.
8028
+
8029
+ [*Note 1*: The expression is potentially evaluated [[basic.def.odr]].
8030
+ The use of assumptions is intended to allow implementations to analyze
8031
+ the form of the expression and deduce information used to optimize the
8032
+ program. Implementations are not required to deduce any information from
8033
+ any particular assumption. It is expected that the value of a
8034
+ *has-attribute-expression* for the `assume` attribute is `0` if an
8035
+ implementation does not attempt to deduce any such information from
8036
+ assumptions. — *end note*]
8037
+
8038
+ [*Example 1*:
8039
+
8040
+ ``` cpp
8041
+ int divide_by_32(int x) {
8042
+ [[assume(x >= 0)]];
8043
+ return x/32; // The instructions produced for the division
8044
+ // may omit handling of negative values.
8045
+ }
8046
+ int f(int y) {
8047
+ [[assume(++y == 43)]]; // y is not incremented
8048
+ return y; // statement may be replaced with return 42;
8049
+ }
8050
+ ```
8051
+
8052
+ — *end example*]
8053
+
8054
+ ### Deprecated attribute <a id="dcl.attr.deprecated">[[dcl.attr.deprecated]]</a>
8055
+
8056
+ The *attribute-token* `deprecated` can be used to mark names and
8057
+ entities whose use is still allowed, but is discouraged for some reason.
8058
+
8059
+ [*Note 1*: In particular, `deprecated` is appropriate for names and
8060
+ entities that are deemed obsolescent or unsafe. — *end note*]
8061
+
8062
+ An *attribute-argument-clause* may be present and, if present, it shall
8063
+ have the form:
8064
+
8065
+ ``` bnf
8066
+ '(' unevaluated-string ')'
8067
+ ```
8068
+
8069
+ [*Note 2*: The *unevaluated-string* in the *attribute-argument-clause*
8070
+ can be used to explain the rationale for deprecation and/or to suggest a
8071
+ replacing entity. — *end note*]
8072
+
8073
+ The attribute may be applied to the declaration of a class, a type
8074
+ alias, a variable, a non-static data member, a function, a namespace, an
8075
+ enumeration, an enumerator, a concept, or a template specialization.
8076
+
8077
+ An entity declared without the `deprecated` attribute can later be
8078
+ redeclared with the attribute and vice-versa.
8079
+
8080
+ [*Note 3*: Thus, an entity initially declared without the attribute can
8081
+ be marked as deprecated by a subsequent redeclaration. However, after an
8082
+ entity is marked as deprecated, later redeclarations do not un-deprecate
8083
+ the entity. — *end note*]
8084
+
8085
+ Redeclarations using different forms of the attribute (with or without
8086
+ the *attribute-argument-clause* or with different
8087
+ *attribute-argument-clause*s) are allowed.
8088
+
8089
+ *Recommended practice:* Implementations should use the `deprecated`
8090
+ attribute to produce a diagnostic message in case the program refers to
8091
+ a name or entity other than to declare it, after a declaration that
8092
+ specifies the attribute. The diagnostic message should include the text
8093
+ provided within the *attribute-argument-clause* of any `deprecated`
8094
+ attribute applied to the name or entity. The value of a
8095
+ *has-attribute-expression* for the `deprecated` attribute should be `0`
8096
+ unless the implementation can issue such diagnostic messages.
8097
+
8098
+ ### Fallthrough attribute <a id="dcl.attr.fallthrough">[[dcl.attr.fallthrough]]</a>
8099
+
8100
+ The *attribute-token* `fallthrough` may be applied to a null statement
8101
+ [[stmt.expr]]; such a statement is a *fallthrough statement*. No
8102
+ *attribute-argument-clause* shall be present. A fallthrough statement
8103
+ may only appear within an enclosing `switch` statement [[stmt.switch]].
8104
+ The next statement that would be executed after a fallthrough statement
8105
+ shall be a labeled statement whose label is a case label or default
8106
+ label for the same `switch` statement and, if the fallthrough statement
8107
+ is contained in an iteration statement, the next statement shall be part
8108
+ of the same execution of the substatement of the innermost enclosing
8109
+ iteration statement. The program is ill-formed if there is no such
8110
+ statement.
8111
+
8112
+ *Recommended practice:* The use of a fallthrough statement should
8113
+ suppress a warning that an implementation might otherwise issue for a
8114
+ case or default label that is reachable from another case or default
8115
+ label along some path of execution. The value of a
8116
+ *has-attribute-expression* for the `fallthrough` attribute should be `0`
8117
+ if the attribute does not cause suppression of such warnings.
8118
+ Implementations should issue a warning if a fallthrough statement is not
8119
+ dynamically reachable.
8120
+
8121
+ [*Example 1*:
8122
+
8123
+ ``` cpp
8124
+ void f(int n) {
8125
+ void g(), h(), i();
8126
+ switch (n) {
8127
+ case 1:
8128
+ case 2:
8129
+ g();
8130
+ [[fallthrough]];
8131
+ case 3: // warning on fallthrough discouraged
8132
+ do {
8133
+ [[fallthrough]]; // error: next statement is not part of the same substatement execution
8134
+ } while (false);
8135
+ case 6:
8136
+ do {
8137
+ [[fallthrough]]; // error: next statement is not part of the same substatement execution
8138
+ } while (n--);
8139
+ case 7:
8140
+ while (false) {
8141
+ [[fallthrough]]; // error: next statement is not part of the same substatement execution
8142
+ }
8143
+ case 5:
8144
+ h();
8145
+ case 4: // implementation may warn on fallthrough
8146
+ i();
8147
+ [[fallthrough]]; // error
8148
+ }
8149
+ }
8150
+ ```
8151
+
8152
+ — *end example*]
8153
+
8154
+ ### Indeterminate storage <a id="dcl.attr.indet">[[dcl.attr.indet]]</a>
8155
+
8156
+ The *attribute-token* `indeterminate` may be applied to the definition
8157
+ of a block variable with automatic storage duration or to a
8158
+ *parameter-declaration* of a function declaration. No
8159
+ *attribute-argument-clause* shall be present. The attribute specifies
8160
+ that the storage of an object with automatic storage duration is
8161
+ initially indeterminate rather than erroneous [[basic.indet]].
8162
+
8163
+ If a function parameter is declared with the `indeterminate` attribute,
8164
+ it shall be so declared in the first declaration of its function. If a
8165
+ function parameter is declared with the `indeterminate` attribute in the
8166
+ first declaration of its function in one translation unit and the same
8167
+ function is declared without the `indeterminate` attribute on the same
8168
+ parameter in its first declaration in another translation unit, the
8169
+ program is ill-formed, no diagnostic required.
8170
+
8171
+ [*Note 1*:
8172
+
8173
+ Reading from an uninitialized variable that is marked
8174
+ `[[indeterminate]]` can cause undefined behavior.
8175
+
8176
+ ``` cpp
8177
+ void f(int);
8178
+ void g() {
8179
+ int x [[indeterminate]], y;
8180
+ f(y); // erroneous behavior[basic.indet]
8181
+ f(x); // undefined behavior
8182
+ }
8183
+
8184
+ struct T {
8185
+ T() {}
8186
+ int x;
8187
+ };
8188
+ int h(T t [[indeterminate]]) {
8189
+ f(t.x); // undefined behavior when called below
8190
+ return 0;
8191
+ }
8192
+ int _ = h(T());
8193
+ ```
8194
+
8195
+ — *end note*]
8196
+
8197
+ ### Likelihood attributes <a id="dcl.attr.likelihood">[[dcl.attr.likelihood]]</a>
8198
+
8199
+ The *attribute-token*s `likely` and `unlikely` may be applied to labels
8200
+ or statements. No *attribute-argument-clause* shall be present. The
8201
+ *attribute-token* `likely` shall not appear in an
8202
+ *attribute-specifier-seq* that contains the *attribute-token*
8203
+ `unlikely`.
8204
+
8205
+ [*Note 1*: The use of the `likely` attribute is intended to allow
8206
+ implementations to optimize for the case where paths of execution
8207
+ including it are arbitrarily more likely than any alternative path of
8208
+ execution that does not include such an attribute on a statement or
8209
+ label. The use of the `unlikely` attribute is intended to allow
8210
+ implementations to optimize for the case where paths of execution
8211
+ including it are arbitrarily more unlikely than any alternative path of
8212
+ execution that does not include such an attribute on a statement or
8213
+ label. It is expected that the value of a *has-attribute-expression* for
8214
+ the `likely` and `unlikely` attributes is `0` if the implementation does
8215
+ not attempt to use these attributes for such optimizations. A path of
8216
+ execution includes a label if and only if it contains a jump to that
8217
+ label. — *end note*]
8218
+
8219
+ [*Note 2*: Excessive usage of either of these attributes is liable to
8220
+ result in performance degradation. — *end note*]
8221
+
8222
+ [*Example 1*:
8223
+
8224
+ ``` cpp
8225
+ void g(int);
8226
+ int f(int n) {
8227
+ if (n > 5) [[unlikely]] { // n > 5 is considered to be arbitrarily unlikely
8228
+ g(0);
8229
+ return n * 2 + 1;
8230
+ }
8231
+
8232
+ switch (n) {
8233
+ case 1:
8234
+ g(1);
8235
+ [[fallthrough]];
8236
+
8237
+ [[likely]] case 2: // n == 2 is considered to be arbitrarily more
8238
+ g(2); // likely than any other value of n
8239
+ break;
8240
+ }
8241
+ return 3;
8242
+ }
8243
+ ```
8244
+
8245
+ — *end example*]
8246
+
8247
+ ### Maybe unused attribute <a id="dcl.attr.unused">[[dcl.attr.unused]]</a>
8248
+
8249
+ The *attribute-token* `maybe_unused` indicates that a name, label, or
8250
+ entity is possibly intentionally unused. No *attribute-argument-clause*
8251
+ shall be present.
8252
+
8253
+ The attribute may be applied to the declaration of a class, type alias,
8254
+ variable (including a structured binding declaration), structured
8255
+ binding, result binding [[dcl.contract.res]], non-static data member,
8256
+ function, enumeration, or enumerator, or to an *identifier* label
8257
+ [[stmt.label]].
8258
+
8259
+ A name or entity declared without the `maybe_unused` attribute can later
8260
+ be redeclared with the attribute and vice versa. An entity is considered
8261
+ marked after the first declaration that marks it.
8262
+
8263
+ *Recommended practice:* For an entity marked `maybe_unused`,
8264
+ implementations should not emit a warning that the entity or its
8265
+ structured bindings (if any) are used or unused. For a structured
8266
+ binding declaration not marked `maybe_unused`, implementations should
8267
+ not emit such a warning unless all of its structured bindings are
8268
+ unused. For a label to which `maybe_unused` is applied, implementations
8269
+ should not emit a warning that the label is used or unused. The value of
8270
+ a *has-attribute-expression* for the `maybe_unused` attribute should be
8271
+ `0` if the attribute does not cause suppression of such warnings.
8272
+
8273
+ [*Example 1*:
8274
+
8275
+ ``` cpp
8276
+ [[maybe_unused]] void f([[maybe_unused]] bool thing1,
8277
+ [[maybe_unused]] bool thing2) {
8278
+ [[maybe_unused]] bool b = thing1 && thing2;
8279
+ assert(b);
8280
+ #ifdef NDEBUG
8281
+ goto x;
8282
+ #endif
8283
+ [[maybe_unused]] x:
8284
+ }
8285
+ ```
8286
+
8287
+ Implementations should not warn that `b` or `x` is unused, whether or
8288
+ not `NDEBUG` is defined.
8289
+
8290
+ — *end example*]
8291
+
8292
+ ### Nodiscard attribute <a id="dcl.attr.nodiscard">[[dcl.attr.nodiscard]]</a>
8293
+
8294
+ The *attribute-token* `nodiscard` may be applied to a function or a
8295
+ lambda call operator or to the declaration of a class or enumeration. An
8296
+ *attribute-argument-clause* may be present and, if present, shall have
8297
+ the form:
8298
+
8299
+ ``` bnf
8300
+ '(' unevaluated-string ')'
8301
+ ```
8302
+
8303
+ A name or entity declared without the `nodiscard` attribute can later be
8304
+ redeclared with the attribute and vice-versa.
8305
+
8306
+ [*Note 1*: Thus, an entity initially declared without the attribute can
8307
+ be marked as `nodiscard` by a subsequent redeclaration. However, after
8308
+ an entity is marked as `nodiscard`, later redeclarations do not remove
8309
+ the `nodiscard` from the entity. — *end note*]
8310
+
8311
+ Redeclarations using different forms of the attribute (with or without
8312
+ the *attribute-argument-clause* or with different
8313
+ *attribute-argument-clause*s) are allowed.
8314
+
8315
+ A *nodiscard type* is a (possibly cv-qualified) class or enumeration
8316
+ type marked `nodiscard` in a reachable declaration. A *nodiscard call*
8317
+ is either
8318
+
8319
+ - a function call expression [[expr.call]] that calls a function
8320
+ declared `nodiscard` in a reachable declaration or whose return type
8321
+ is a nodiscard type, or
8322
+ - an explicit type conversion
8323
+ [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]] that
8324
+ constructs an object through a constructor declared `nodiscard` in a
8325
+ reachable declaration, or that initializes an object of a nodiscard
8326
+ type.
8327
+
8328
+ *Recommended practice:* Appearance of a nodiscard call as a
8329
+ potentially-evaluated discarded-value expression [[expr.prop]] of
8330
+ non-void type is discouraged unless explicitly cast to `void`.
8331
+ Implementations should issue a warning in such cases. The value of a
8332
+ *has-attribute-expression* for the `nodiscard` attribute should be `0`
8333
+ unless the implementation can issue such warnings.
8334
+
8335
+ [*Note 2*: This is typically because discarding the return value of a
8336
+ nodiscard call has surprising consequences. — *end note*]
8337
+
8338
+ The *unevaluated-string* in a `nodiscard` *attribute-argument-clause*
8339
+ should be used in the message of the warning as the rationale for why
8340
+ the result should not be discarded.
8341
+
8342
+ [*Example 1*:
8343
+
8344
+ ``` cpp
8345
+ struct [[nodiscard]] my_scopeguard { ... };
8346
+ struct my_unique {
8347
+ my_unique() = default; // does not acquire resource
8348
+ [[nodiscard]] my_unique(int fd) { ... } // acquires resource
8349
+ ~my_unique() noexcept { ... } // releases resource, if any
8350
+ ...
8351
+ };
8352
+ struct [[nodiscard]] error_info { ... };
8353
+ error_info enable_missile_safety_mode();
8354
+ void launch_missiles();
8355
+ void test_missiles() {
8356
+ my_scopeguard(); // warning encouraged
8357
+ (void)my_scopeguard(), // warning not encouraged, cast to void
8358
+ launch_missiles(); // comma operator, statement continues
8359
+ my_unique(42); // warning encouraged
8360
+ my_unique(); // warning not encouraged
8361
+ enable_missile_safety_mode(); // warning encouraged
8362
+ launch_missiles();
8363
+ }
8364
+ error_info &foo();
8365
+ void f() { foo(); } // warning not encouraged: not a nodiscard call, because neither
8366
+ // the (reference) return type nor the function is declared nodiscard
8367
+ ```
8368
+
8369
+ — *end example*]
8370
+
8371
+ ### Noreturn attribute <a id="dcl.attr.noreturn">[[dcl.attr.noreturn]]</a>
8372
+
8373
+ The *attribute-token* `noreturn` specifies that a function does not
8374
+ return. No *attribute-argument-clause* shall be present. The attribute
8375
+ may be applied to a function or a lambda call operator. The first
8376
+ declaration of a function shall specify the `noreturn` attribute if any
8377
+ declaration of that function specifies the `noreturn` attribute. If a
8378
+ function is declared with the `noreturn` attribute in one translation
8379
+ unit and the same function is declared without the `noreturn` attribute
8380
+ in another translation unit, the program is ill-formed, no diagnostic
8381
+ required.
8382
+
8383
+ If a function `f` is invoked where `f` was previously declared with the
8384
+ `noreturn` attribute and that invocation eventually returns, the
8385
+ behavior is runtime-undefined.
8386
+
8387
+ [*Note 1*: The function can terminate by throwing an
8388
+ exception. — *end note*]
8389
+
8390
+ *Recommended practice:* Implementations should issue a warning if a
8391
+ function marked `[[noreturn]]` might return. The value of a
8392
+ *has-attribute-expression* for the `noreturn` attribute should be `0`
8393
+ unless the implementation can issue such warnings.
8394
+
8395
+ [*Example 1*:
8396
+
8397
+ ``` cpp
8398
+ [[ noreturn ]] void f() {
8399
+ throw "error"; // OK
8400
+ }
8401
+
8402
+ [[ noreturn ]] void q(int i) { // behavior is undefined if called with an argument <= 0
8403
+ if (i > 0)
8404
+ throw "positive";
8405
+ }
8406
+ ```
8407
+
8408
+ — *end example*]
8409
+
8410
+ ### No unique address attribute <a id="dcl.attr.nouniqueaddr">[[dcl.attr.nouniqueaddr]]</a>
8411
+
8412
+ The *attribute-token* `no_unique_address` specifies that a non-static
8413
+ data member is a potentially-overlapping subobject [[intro.object]]. No
8414
+ *attribute-argument-clause* shall be present. The attribute may
8415
+ appertain to a non-static data member other than a bit-field.
8416
+
8417
+ [*Note 1*: The non-static data member can share the address of another
8418
+ non-static data member or that of a base class, and any padding that
8419
+ would normally be inserted at the end of the object can be reused as
8420
+ storage for other members. — *end note*]
8421
+
8422
+ *Recommended practice:* The value of a *has-attribute-expression* for
8423
+ the `no_unique_address` attribute should be `0` for a given
8424
+ implementation unless this attribute can cause a potentially-overlapping
8425
+ subobject to have zero size.
8426
+
8427
+ [*Example 1*:
8428
+
8429
+ ``` cpp
8430
+ template<typename Key, typename Value,
8431
+ typename Hash, typename Pred, typename Allocator>
8432
+ class hash_map {
8433
+ [[no_unique_address]] Hash hasher;
8434
+ [[no_unique_address]] Pred pred;
8435
+ [[no_unique_address]] Allocator alloc;
8436
+ Bucket *buckets;
8437
+ // ...
8438
+ public:
8439
+ // ...
8440
+ };
8441
+ ```
8442
+
8443
+ Here, `hasher`, `pred`, and `alloc` could have the same address as
8444
+ `buckets` if their respective types are all empty.
8445
+
8446
+ — *end example*]
8447
+
8448
+ ### Annotations <a id="dcl.attr.annotation">[[dcl.attr.annotation]]</a>
8449
+
8450
+ An annotation may be applied to any declaration of a type, type alias,
8451
+ variable, function, namespace, enumerator, *base-specifier*, or
8452
+ non-static data member.
8453
+
8454
+ Let E be the expression
8455
+ `std::meta::reflect_constant(constant-expression)`. E shall be a
8456
+ constant expression; the result of E is the *underlying constant* of the
8457
+ annotation.
8458
+
8459
+ Each *annotation* produces a unique annotation.
8460
+
8461
+ Substituting into an *annotation* is not in the immediate context.
8462
+
8463
+ [*Example 1*:
8464
+
8465
+ ``` cpp
8466
+ [[=1]] void f();
8467
+ [[=2, =3, =2]] void g();
8468
+ void g [[=4, =2]] ();
8469
+ ```
8470
+
8471
+ `f` has one annotation and `g` has five annotations. These can be
8472
+ queried with metafunctions such as `std::{}meta::{}annotations_of`
8473
+ [[meta.reflection.annotation]].
8474
+
8475
+ — *end example*]
8476
+
8477
+ [*Example 2*:
8478
+
8479
+ ``` cpp
8480
+ template<class T>
8481
+ [[=T::type()]] void f(T t);
8482
+
8483
+ void f(int);
8484
+
8485
+ void g() {
8486
+ f(0); // OK
8487
+ f('0'); // error, substituting into the annotation results in an invalid expression
8488
+ }
8489
+ ```
8490
+
8491
+ — *end example*]
8492
+
8493
+ <!-- Link reference definitions -->
8494
+ [basic.align]: basic.md#basic.align
8495
+ [basic.compound]: basic.md#basic.compound
8496
+ [basic.contract.general]: basic.md#basic.contract.general
8497
+ [basic.def]: basic.md#basic.def
8498
+ [basic.def.odr]: basic.md#basic.def.odr
8499
+ [basic.fundamental]: basic.md#basic.fundamental
8500
+ [basic.indet]: basic.md#basic.indet
8501
+ [basic.life]: basic.md#basic.life
8502
+ [basic.link]: basic.md#basic.link
8503
+ [basic.lookup]: basic.md#basic.lookup
8504
+ [basic.lookup.argdep]: basic.md#basic.lookup.argdep
8505
+ [basic.lookup.elab]: basic.md#basic.lookup.elab
8506
+ [basic.lookup.general]: basic.md#basic.lookup.general
8507
+ [basic.lookup.qual]: basic.md#basic.lookup.qual
8508
+ [basic.lookup.udir]: basic.md#basic.lookup.udir
8509
+ [basic.lookup.unqual]: basic.md#basic.lookup.unqual
8510
+ [basic.lval]: expr.md#basic.lval
8511
+ [basic.namespace]: #basic.namespace
8512
+ [basic.namespace.general]: #basic.namespace.general
8513
+ [basic.pre]: basic.md#basic.pre
8514
+ [basic.scope.namespace]: basic.md#basic.scope.namespace
8515
+ [basic.scope.scope]: basic.md#basic.scope.scope
8516
+ [basic.start]: basic.md#basic.start
8517
+ [basic.start.dynamic]: basic.md#basic.start.dynamic
8518
+ [basic.start.static]: basic.md#basic.start.static
8519
+ [basic.stc]: basic.md#basic.stc
8520
+ [basic.stc.auto]: basic.md#basic.stc.auto
8521
+ [basic.stc.dynamic]: basic.md#basic.stc.dynamic
8522
+ [basic.stc.dynamic.allocation]: basic.md#basic.stc.dynamic.allocation
8523
+ [basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
8524
+ [basic.stc.static]: basic.md#basic.stc.static
8525
+ [basic.stc.thread]: basic.md#basic.stc.thread
8526
+ [basic.type.qualifier]: basic.md#basic.type.qualifier
8527
+ [class]: class.md#class
8528
+ [class.access]: class.md#class.access
8529
+ [class.access.base]: class.md#class.access.base
8530
+ [class.base.init]: class.md#class.base.init
8531
+ [class.bit]: class.md#class.bit
8532
+ [class.compare.default]: class.md#class.compare.default
8533
+ [class.conv.ctor]: class.md#class.conv.ctor
8534
+ [class.conv.fct]: class.md#class.conv.fct
8535
+ [class.copy.assign]: class.md#class.copy.assign
8536
+ [class.copy.ctor]: class.md#class.copy.ctor
8537
+ [class.copy.elision]: class.md#class.copy.elision
8538
+ [class.ctor]: class.md#class.ctor
8539
+ [class.default.ctor]: class.md#class.default.ctor
8540
+ [class.dtor]: class.md#class.dtor
8541
+ [class.expl.init]: class.md#class.expl.init
8542
+ [class.friend]: class.md#class.friend
8543
+ [class.inhctor.init]: class.md#class.inhctor.init
8544
+ [class.init]: class.md#class.init
8545
+ [class.mem]: class.md#class.mem
8546
+ [class.mem.general]: class.md#class.mem.general
8547
+ [class.member.lookup]: basic.md#class.member.lookup
8548
+ [class.mfct]: class.md#class.mfct
8549
+ [class.mi]: class.md#class.mi
8550
+ [class.name]: class.md#class.name
8551
+ [class.pre]: class.md#class.pre
8552
+ [class.qual]: basic.md#class.qual
8553
+ [class.static]: class.md#class.static
8554
+ [class.static.data]: class.md#class.static.data
8555
+ [class.temporary]: basic.md#class.temporary
8556
+ [class.union]: class.md#class.union
8557
+ [class.union.anon]: class.md#class.union.anon
8558
+ [class.virtual]: class.md#class.virtual
8559
+ [conv]: expr.md#conv
8560
+ [conv.array]: expr.md#conv.array
8561
+ [conv.func]: expr.md#conv.func
8562
+ [conv.general]: expr.md#conv.general
8563
+ [conv.integral]: expr.md#conv.integral
8564
+ [conv.lval]: expr.md#conv.lval
8565
+ [conv.prom]: expr.md#conv.prom
8566
+ [conv.ptr]: expr.md#conv.ptr
8567
+ [conv.qual]: expr.md#conv.qual
8568
+ [conv.rval]: expr.md#conv.rval
8569
+ [coroutine.handle]: support.md#coroutine.handle
8570
+ [coroutine.handle.resumption]: support.md#coroutine.handle.resumption
8571
+ [csetjmp.syn]: support.md#csetjmp.syn
8572
+ [dcl]: #dcl
8573
+ [dcl.align]: #dcl.align
8574
+ [dcl.ambig.res]: #dcl.ambig.res
8575
+ [dcl.array]: #dcl.array
8576
+ [dcl.asm]: #dcl.asm
8577
+ [dcl.attr]: #dcl.attr
8578
+ [dcl.attr.annotation]: #dcl.attr.annotation
8579
+ [dcl.attr.assume]: #dcl.attr.assume
8580
+ [dcl.attr.deprecated]: #dcl.attr.deprecated
8581
+ [dcl.attr.fallthrough]: #dcl.attr.fallthrough
8582
+ [dcl.attr.grammar]: #dcl.attr.grammar
8583
+ [dcl.attr.indet]: #dcl.attr.indet
8584
+ [dcl.attr.likelihood]: #dcl.attr.likelihood
8585
+ [dcl.attr.nodiscard]: #dcl.attr.nodiscard
8586
+ [dcl.attr.noreturn]: #dcl.attr.noreturn
8587
+ [dcl.attr.nouniqueaddr]: #dcl.attr.nouniqueaddr
8588
+ [dcl.attr.unused]: #dcl.attr.unused
8589
+ [dcl.constexpr]: #dcl.constexpr
8590
+ [dcl.constinit]: #dcl.constinit
8591
+ [dcl.contract]: #dcl.contract
8592
+ [dcl.contract.func]: #dcl.contract.func
8593
+ [dcl.contract.res]: #dcl.contract.res
8594
+ [dcl.decl]: #dcl.decl
8595
+ [dcl.decl.general]: #dcl.decl.general
8596
+ [dcl.enum]: #dcl.enum
8597
+ [dcl.fct]: #dcl.fct
8598
+ [dcl.fct.def]: #dcl.fct.def
8599
+ [dcl.fct.def.coroutine]: #dcl.fct.def.coroutine
8600
+ [dcl.fct.def.default]: #dcl.fct.def.default
8601
+ [dcl.fct.def.delete]: #dcl.fct.def.delete
8602
+ [dcl.fct.def.general]: #dcl.fct.def.general
8603
+ [dcl.fct.def.replace]: #dcl.fct.def.replace
8604
+ [dcl.fct.default]: #dcl.fct.default
8605
+ [dcl.fct.spec]: #dcl.fct.spec
8606
+ [dcl.friend]: #dcl.friend
8607
+ [dcl.init]: #dcl.init
8608
+ [dcl.init.aggr]: #dcl.init.aggr
8609
+ [dcl.init.general]: #dcl.init.general
8610
+ [dcl.init.list]: #dcl.init.list
8611
+ [dcl.init.ref]: #dcl.init.ref
8612
+ [dcl.init.string]: #dcl.init.string
8613
+ [dcl.inline]: #dcl.inline
8614
+ [dcl.link]: #dcl.link
8615
+ [dcl.meaning]: #dcl.meaning
8616
+ [dcl.meaning.general]: #dcl.meaning.general
8617
+ [dcl.mptr]: #dcl.mptr
8618
+ [dcl.name]: #dcl.name
8619
+ [dcl.pre]: #dcl.pre
8620
+ [dcl.ptr]: #dcl.ptr
8621
+ [dcl.ref]: #dcl.ref
8622
+ [dcl.spec]: #dcl.spec
8623
+ [dcl.spec.auto]: #dcl.spec.auto
8624
+ [dcl.spec.auto.general]: #dcl.spec.auto.general
8625
+ [dcl.spec.general]: #dcl.spec.general
8626
+ [dcl.stc]: #dcl.stc
8627
+ [dcl.struct.bind]: #dcl.struct.bind
8628
+ [dcl.type]: #dcl.type
8629
+ [dcl.type.auto.deduct]: #dcl.type.auto.deduct
8630
+ [dcl.type.class.deduct]: #dcl.type.class.deduct
8631
+ [dcl.type.cv]: #dcl.type.cv
8632
+ [dcl.type.decltype]: #dcl.type.decltype
8633
+ [dcl.type.elab]: #dcl.type.elab
8634
+ [dcl.type.general]: #dcl.type.general
8635
+ [dcl.type.pack.index]: #dcl.type.pack.index
8636
+ [dcl.type.simple]: #dcl.type.simple
8637
+ [dcl.type.splice]: #dcl.type.splice
8638
+ [dcl.typedef]: #dcl.typedef
8639
+ [depr.ellipsis.comma]: future.md#depr.ellipsis.comma
8640
+ [depr.volatile.type]: future.md#depr.volatile.type
8641
+ [enum]: #enum
8642
+ [enum.udecl]: #enum.udecl
8643
+ [except.ctor]: except.md#except.ctor
8644
+ [except.handle]: except.md#except.handle
8645
+ [except.pre]: except.md#except.pre
8646
+ [except.spec]: except.md#except.spec
8647
+ [except.throw]: except.md#except.throw
8648
+ [expr.alignof]: expr.md#expr.alignof
8649
+ [expr.assign]: expr.md#expr.assign
8650
+ [expr.await]: expr.md#expr.await
8651
+ [expr.call]: expr.md#expr.call
8652
+ [expr.cast]: expr.md#expr.cast
8653
+ [expr.comma]: expr.md#expr.comma
8654
+ [expr.const]: expr.md#expr.const
8655
+ [expr.const.cast]: expr.md#expr.const.cast
8656
+ [expr.mptr.oper]: expr.md#expr.mptr.oper
8657
+ [expr.new]: expr.md#expr.new
8658
+ [expr.post.incr]: expr.md#expr.post.incr
8659
+ [expr.pre.incr]: expr.md#expr.pre.incr
8660
+ [expr.prim.id]: expr.md#expr.prim.id
8661
+ [expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
8662
+ [expr.prim.lambda]: expr.md#expr.prim.lambda
8663
+ [expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
8664
+ [expr.prim.this]: expr.md#expr.prim.this
8665
+ [expr.prop]: expr.md#expr.prop
8666
+ [expr.ref]: expr.md#expr.ref
8667
+ [expr.reflect]: expr.md#expr.reflect
8668
+ [expr.static.cast]: expr.md#expr.static.cast
8669
+ [expr.sub]: expr.md#expr.sub
8670
+ [expr.throw]: expr.md#expr.throw
8671
+ [expr.type.conv]: expr.md#expr.type.conv
8672
+ [expr.unary]: expr.md#expr.unary
8673
+ [expr.unary.op]: expr.md#expr.unary.op
8674
+ [expr.yield]: expr.md#expr.yield
8675
+ [initializer.list.syn]: support.md#initializer.list.syn
8676
+ [intro.abstract]: intro.md#intro.abstract
8677
+ [intro.execution]: basic.md#intro.execution
8678
+ [intro.object]: basic.md#intro.object
8679
+ [intro.races]: basic.md#intro.races
8680
+ [lex.charset]: lex.md#lex.charset
8681
+ [lex.digraph]: lex.md#lex.digraph
8682
+ [lex.key]: lex.md#lex.key
8683
+ [lex.name]: lex.md#lex.name
8684
+ [lex.phases]: lex.md#lex.phases
8685
+ [lex.string]: lex.md#lex.string
8686
+ [lex.string.uneval]: lex.md#lex.string.uneval
8687
+ [meta.reflection.annotation]: meta.md#meta.reflection.annotation
8688
+ [module.interface]: module.md#module.interface
8689
+ [module.reach]: module.md#module.reach
8690
+ [module.unit]: module.md#module.unit
8691
+ [namespace.alias]: #namespace.alias
8692
+ [namespace.def]: #namespace.def
8693
+ [namespace.def.general]: #namespace.def.general
8694
+ [namespace.qual]: basic.md#namespace.qual
8695
+ [namespace.udecl]: #namespace.udecl
8696
+ [namespace.udir]: #namespace.udir
8697
+ [namespace.unnamed]: #namespace.unnamed
8698
+ [over]: over.md#over
8699
+ [over.binary]: over.md#over.binary
8700
+ [over.literal]: over.md#over.literal
8701
+ [over.match]: over.md#over.match
8702
+ [over.match.best]: over.md#over.match.best
8703
+ [over.match.class.deduct]: over.md#over.match.class.deduct
8704
+ [over.match.conv]: over.md#over.match.conv
8705
+ [over.match.copy]: over.md#over.match.copy
8706
+ [over.match.ctor]: over.md#over.match.ctor
8707
+ [over.match.funcs]: over.md#over.match.funcs
8708
+ [over.match.list]: over.md#over.match.list
8709
+ [over.match.ref]: over.md#over.match.ref
8710
+ [over.match.viable]: over.md#over.match.viable
8711
+ [over.oper]: over.md#over.oper
8712
+ [over.sub]: over.md#over.sub
8713
+ [special]: class.md#special
8714
+ [std.modules]: library.md#std.modules
8715
+ [stmt]: stmt.md#stmt
8716
+ [stmt.ambig]: stmt.md#stmt.ambig
8717
+ [stmt.dcl]: stmt.md#stmt.dcl
8718
+ [stmt.expr]: stmt.md#stmt.expr
8719
+ [stmt.if]: stmt.md#stmt.if
8720
+ [stmt.iter]: stmt.md#stmt.iter
8721
+ [stmt.label]: stmt.md#stmt.label
8722
+ [stmt.pre]: stmt.md#stmt.pre
8723
+ [stmt.return]: stmt.md#stmt.return
8724
+ [stmt.return.coroutine]: stmt.md#stmt.return.coroutine
8725
+ [stmt.select]: stmt.md#stmt.select
8726
+ [stmt.switch]: stmt.md#stmt.switch
8727
+ [support.runtime]: support.md#support.runtime
8728
+ [temp.arg.nontype]: temp.md#temp.arg.nontype
8729
+ [temp.arg.type]: temp.md#temp.arg.type
8730
+ [temp.decls]: temp.md#temp.decls
8731
+ [temp.deduct]: temp.md#temp.deduct
8732
+ [temp.deduct.call]: temp.md#temp.deduct.call
8733
+ [temp.deduct.decl]: temp.md#temp.deduct.decl
8734
+ [temp.deduct.guide]: temp.md#temp.deduct.guide
8735
+ [temp.dep.type]: temp.md#temp.dep.type
8736
+ [temp.expl.spec]: temp.md#temp.expl.spec
8737
+ [temp.explicit]: temp.md#temp.explicit
8738
+ [temp.fct]: temp.md#temp.fct
8739
+ [temp.inst]: temp.md#temp.inst
8740
+ [temp.local]: temp.md#temp.local
8741
+ [temp.names]: temp.md#temp.names
8742
+ [temp.param]: temp.md#temp.param
8743
+ [temp.pre]: temp.md#temp.pre
8744
+ [temp.res]: temp.md#temp.res
8745
+ [temp.res.general]: temp.md#temp.res.general
8746
+ [temp.spec.general]: temp.md#temp.spec.general
8747
+ [temp.spec.partial]: temp.md#temp.spec.partial
8748
+ [temp.variadic]: temp.md#temp.variadic
8749
+ [term.odr.use]: basic.md#term.odr.use
8750
+ [term.padding.bits]: basic.md#term.padding.bits
8751
+ [term.scalar.type]: basic.md#term.scalar.type
8752
+ [term.unevaluated.operand]: expr.md#term.unevaluated.operand
8753
+
8754
+ [^1]: There is no special provision for a *decl-specifier-seq* that
8755
+ lacks a *type-specifier* or that has a *type-specifier* that only
8756
+ specifies *cv-qualifier*s. The “implicit int” rule of C is no longer
8757
+ supported.
8758
+
8759
+ [^2]: As indicated by syntax, cv-qualifiers are a significant component
8760
+ in function return types.
8761
+
8762
+ [^3]: One can explicitly disambiguate the parse either by introducing a
8763
+ comma (so the ellipsis will be parsed as part of the
8764
+ *parameter-declaration-clause*) or by introducing a name for the
8765
+ parameter (so the ellipsis will be parsed as part of the
8766
+ *declarator-id*).
8767
+
8768
+ [^4]: This means that default arguments cannot appear, for example, in
8769
+ declarations of pointers to functions, references to functions, or
8770
+ `typedef` declarations.
8771
+
8772
+ [^5]: As specified in  [[conv.ptr]], converting an integer literal whose
8773
+ value is `0` to a pointer type results in a null pointer value.
8774
+
8775
+ [^6]: The syntax provides for empty *braced-init-list*s, but nonetheless
8776
+ C++ does not have zero length arrays.
8777
+
8778
+ [^7]: This requires a conversion function [[class.conv.fct]] returning a
8779
+ reference type.
8780
+
8781
+ [^8]: Implementations are permitted to provide additional predefined
8782
+ variables with names that are reserved to the implementation
8783
+ [[lex.name]]. If a predefined variable is not odr-used
8784
+ [[term.odr.use]], its string value need not be present in the
8785
+ program image.
8786
+
8787
+ [^9]: This set of values is used to define promotion and conversion
8788
+ semantics for the enumeration type. It does not preclude an
8789
+ expression of enumeration type from having a value that falls
8790
+ outside this range.
8791
+
8792
+ [^10]: During name lookup in a class hierarchy, some ambiguities can be
8793
+ resolved by considering whether one member hides the other along
8794
+ some paths [[class.member.lookup]]. There is no such
8795
+ disambiguation when considering the set of names found as a result
8796
+ of following \*using-directive\*s.
8797
+
8798
+ [^11]: A *using-declaration* with more than one *using-declarator* is
8799
+ equivalent to a corresponding sequence of *using-declaration*s with
8800
+ one *using-declarator* each.