You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Catch up feature documentation and C++26 new headers
Add documentation for:
- tersest syntax (e.g., `:(a,b) a+b;`)
- `unevaluated` contract group
- for `operator++` and `operator--`, that writing the single operator in Cpp2 generates both forms when lowering to Cpp1
- `-cwd` and `-quiet` command line options
Remove documentation for:
- `-add-source-info` switch which was removed
Add support for new C++26 headers approved in St Louis:
- `inplace_vector`
Copy file name to clipboardExpand all lines: docs/cpp2/common.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -220,7 +220,7 @@ Postfix notation lets the code read fluidly left-to-right, in the same order in
220
220
221
221
> Note: The `...` pack expansion syntax is also supported. The above `...` and `..=` are the Cpp2 range operators, which overlap in syntax.
222
222
223
-
> Note: Because `++` and `--` always have in-place update semantics, we never need to remember "use prefix `++`/`--` unless you need a copy of the old value." If you do need a copy of the old value, just take the copy before calling `++`/`--`.
223
+
> Note: Because `++` and `--` always have in-place update semantics, we never need to remember "use prefix `++`/`--` unless you need a copy of the old value." If you do need a copy of the old value, just take the copy before calling `++`/`--`. When you write a type that overloads `operator++` or `operator--`, cppfront generates both Cpp1 overloads (in-place-update and copy-old-value) for that function to support natural use of the type from Cpp1 code.
Copy file name to clipboardExpand all lines: docs/cpp2/contracts.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -15,11 +15,13 @@ Notes:
15
15
16
16
- Optionally, `condition` may be followed by `, "message"`, a message to include if a violation occurs. For example, `pre(condition, "message")`.
17
17
18
-
- Optionally, a `<group, pred1, pred2>` can be written inside `<``>` angle brackets immediately before the `(`, to designate that this test is part of the [contract group](#groups) named `group` and (also optionally) [contract predicates](#predicates)`pred1` and `pred2`. If a violation occurs, `Group.report_violation()` will be called. For example, `pre<group>(condition)`. If no contract group is specified, the contract defaults to being part of the `cpp2_default` group.
18
+
- Optionally, a `<group, pred1, pred2>` can be written inside `<``>` angle brackets immediately before the `(`, to designate that this test is part of the [contract group](#groups) named `group` and (also optionally) [contract predicates](#predicates)`pred1` and `pred2`. If a violation occurs, `Group.report_violation()` will be called. For example, `pre<group>(condition)`. If no contract group is specified, the contract defaults to being part of the `default` group (spelled `cpp2_default` when used from Cpp1 code).
19
19
20
20
The order of evaluation is:
21
21
22
-
- First, predicates are evaluated in order. If any predicte evaluates to `#!cpp false`, stop.
22
+
- First, if the contract group is `unevaluated` then the contract is ignored; `condition` is never evaluated. This special group is designates conditions intended for use by static analyzers only, and the only requirement is that the condition be grammatically valid.
23
+
24
+
- Next, predicates are evaluated in order. If any predicate evaluates to `#!cpp false`, stop.
23
25
24
26
- Next, `group.is_active()` is evaluated. If that evaluates to `#!cpp false`, stop.
Copy file name to clipboardExpand all lines: docs/cpp2/functions.md
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -78,9 +78,13 @@ wrap_f: (
78
78
79
79
A function can return either of the following. The default is `#!cpp -> void`.
80
80
81
-
(1) **`#!cpp -> X`** to return a single unnamed value of type `X`, which can be `#!cpp void` to signify the function has no return value. If `X` is not `#!cpp void`, the function body must have a `#!cpp return /*value*/;` statement that returns a value of type `X` on every path that exits the function. For example:
81
+
(1) **`#!cpp -> X`** to return a single unnamed value of type `X`, which can be `#!cpp void` to signify the function has no return value. If `X` is not `#!cpp void`, the function body must have a `#!cpp return /*value*/;` statement that returns a value of type `X` on every path that exits the function.
82
82
83
-
```cpp title="Functions with an unnamed return value" hl_lines="2 4 7 9 12 14"
83
+
To deduce the return type, write `-> _`. A function whose body returns a single expression `expr` can deduce the return type and omit writing `-> _ = { return /*expr*/ ; }`.
84
+
85
+
For example:
86
+
87
+
```cpp title="Functions with an unnamed return value" hl_lines="2 4 7 9 12 14 15 18 20 22"
(2) **`#!cpp -> ( /* parameter list */ )`** to return a list of named return parameters using the same [parameters](#parameters) syntax, but where the only passing styles are `out` (the default, which moves where possible) or `forward`. The function body must [initialize](objects.md#init) the value of each return-parameter `ret` in its body the same way as any other local variable. An explicit return statement is written just `#!cpp return;` and returns the named values; the function has an implicit `#!cpp return;` at the end. If only a single return parameter is in the list, it is emitted in the lowered Cpp1 code the same way as (1) above, so its name is only available inside the function body.
Copy file name to clipboardExpand all lines: docs/cppfront/options.md
+35-35Lines changed: 35 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -18,13 +18,13 @@ For convenience, you can shorten the name to any unique prefix not shared with a
18
18
-`-import-std` and `-include-std` can be shortened to `-im` and `-in` respectively, but not `-i` which would be ambiguous with each other.
19
19
20
20
21
-
# Basic command line options
21
+
##Basic command line options
22
22
23
-
## `-help`, `-h`, `-?`
23
+
###`-help`, `-h`, `-?`
24
24
25
25
Prints an abbreviated version of this documentation page.
26
26
27
-
## `-import-std`, `-im`
27
+
###`-import-std`, `-im`
28
28
29
29
Makes the entire C++ standard library (namespace `std::`) available via a module `import std.compat;` (which implies `import std;`).
30
30
@@ -34,89 +34,89 @@ This option is implicitly set if `-pure-cpp2` is selected.
34
34
35
35
This option is ignored if `-include-std` is selected. If your Cpp1 compiler does not yet support standard library modules `std` and `std.compat`, this option automatically uses `-include-std` instead as a fallback.
36
36
37
-
## `-include-std`, `-in`
37
+
###`-include-std`, `-in`
38
38
39
39
Makes the entire C++ standard library (namespace `std::`) available via an '#include" of every standard header.
40
40
41
41
This option should always work with all standard headers, including draft-standard C++26 headers that are not yet in a published standard, because it tracks new headers as they are added and uses feature tests to not include headers that are not yet available on your Cpp1 implementation.
42
42
43
-
## `-pure-cpp2`, `-p`
43
+
###`-pure-cpp2`, `-p`
44
44
45
45
Allow Cpp2 syntax only.
46
46
47
47
This option also sets `-import-std`.
48
48
49
-
## `-version`, `-vers`
49
+
###`-version`, `-vers`
50
50
51
51
Print version, build, copyright, and license information.
52
52
53
53
54
-
# Additional dynamic safety checks and contract information
54
+
##Additional dynamic safety checks and contract information
55
55
56
-
## `-add-source-info`, `-a`
57
-
58
-
Enable `source_location` information for contract checks. If this is supported by your Cpp1 compiler, the default contract failure messages will include exact file/line/function information. For example, if the default `Bounds` violation handler would print this without `-a`:
59
-
60
-
Bounds safety violation: out of bounds access attempt detected - attempted access at index 2, [min,max] range is [0,1]
61
-
62
-
then it would print something like this with `-a` (the exact text will vary with the Cpp1 standard library vendor's `source_location` implementation):
63
-
64
-
demo.cpp2(4) int __cdecl main(void): Bounds safety violation: out of bounds access attempt detected - attempted access at index 2, [min,max] range is [0,1]
65
-
66
-
## `-no-comparison-checks`, `-no-c`
56
+
### `-no-comparison-checks`, `-no-c`
67
57
68
58
Disable mixed-sign comparison safety checks. If not disabled, mixed-sign comparisons are diagnosed by default.
69
59
70
-
## `-no-null-checks`, `-no-n`
60
+
###`-no-null-checks`, `-no-n`
71
61
72
62
Disable null safety checks. If not disabled, null dereference checks are performed by default.
73
63
74
-
## `-no-subscript-checks`, `-no-s`
64
+
###`-no-subscript-checks`, `-no-s`
75
65
76
66
Disable subscript bounds safety checks. If not disabled, subscript bounds safety checks are performed by default.
77
67
78
68
79
-
# Support for constrained target environments
69
+
##Support for constrained target environments
80
70
81
-
## `-fno-exceptions`, `-fno-e`
71
+
###`-fno-exceptions`, `-fno-e`
82
72
83
73
Disable C++ exception handling. This should be used only if you must run in an environment that bans C++ exception handling, and so you are already using a similar command line option for your Cpp1 compiler.
84
74
85
75
If this option is selected, a failed `as` for `std::variant` will assert.
86
76
87
-
## `-fno-rtti`, `-fno-r`
77
+
###`-fno-rtti`, `-fno-r`
88
78
89
79
Disable C++ run-time type information (RTTI). This should be used only if you must run in an environment that bans C++ RTTI, and so you are already using a similar command line option for your Cpp1 compiler.
90
80
91
81
If this option is selected, trying to using `as` for `*` (raw pointers) or `std::any` will assert.
92
82
93
83
94
-
#Other options
84
+
## Cpp1 file content options
95
85
96
-
## `-clean-cpp1`, `-c`
86
+
###`-clean-cpp1`, `-cl`
97
87
98
88
Emit clean `.cpp` files without `#line` directives and other extra information that cppfront normally emits in the `.cpp` to light up C++ tools (e.g., to let IDEs integrate cppfront error message output, debuggers step to the right lines in Cpp2 source code, and so forth). In normal use, you won't need `-c`.
99
89
100
-
## `-debug`, `-d`
90
+
###`-emit-cppfront-info`, `-e`
101
91
102
-
Emit compiler debug output. This is only useful when debugging cppfront itself.
92
+
Emit cppfront version and build in the `.cpp` file.
103
93
104
-
## `-emit-cppfront-info`, `-e`
94
+
###`-line-paths`, `-l`
105
95
106
-
Emit cppfront version and build in the `.cpp` file.
96
+
Emit absolute paths in `#line` directives.
107
97
108
-
## `-format-colon-errors`, `-fo`
98
+
## Cppfront output options
109
99
110
-
Emit cppfront diagnostics using `:line:col:` format for line and column numbers, if that is the format better recognized by your IDE, so that it will pick up cppfront messages and integrate them in its normal error message output location. If not set, by default cppfront diagnostics use `(line,col)` format.
100
+
### `-cwd`_path_, `-cw`_path_
111
101
112
-
## `-line-paths`, `-l`
102
+
Changes the current working directory to 'path'. Can be useful in build scripts to control where generated Cpp1 files are places; see also `-output`.
113
103
114
-
Emit absolute paths in `#line` directives.
104
+
### `-debug`, `-d`
115
105
116
-
## `-output`_filename_, `-o`_filename_
106
+
Emit compiler debug output. This is only useful when debugging cppfront itself.
107
+
108
+
### `-format-colon-errors`, `-fo`
109
+
110
+
Emit cppfront diagnostics using `:line:col:` format for line and column numbers, if that is the format better recognized by your IDE, so that it will pick up cppfront messages and integrate them in its normal error message output location. If not set, by default cppfront diagnostics use `(line,col)` format.
111
+
112
+
### `-output`_filename_, `-o`_filename_
117
113
118
114
Output to 'filename' (can be 'stdout'). If not set, the default output filename for is the same as the input filename without the `2` (e.g., compiling `hello.cpp2` by default writes its output to `hello.cpp`, and `header.h2` to `header.h`).
119
115
120
-
## `-verbose`, `-verb`
116
+
### `-quiet`, `-q`
117
+
118
+
Print no console output unless there are errors to report.
0 commit comments