Skip to content

Commit c4eaa46

Browse files
authored
Merge pull request MicrosoftDocs#5067 from MicrosoftDocs/main
10/17/2023 AM Publish
2 parents 7999929 + 4147751 commit c4eaa46

File tree

4 files changed

+109
-65
lines changed

4 files changed

+109
-65
lines changed

docs/build/reference/ifc-map.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
---
22
title: "/ifcMap"
33
description: "Map named modules and header units to IFC files."
4-
ms.date: 10/13/2023
4+
ms.date: 10/16/2023
55
author: "tylermsft"
66
ms.author: "twhitney"
77
f1_keywords: ["/ifcMap"]
88
helpviewer_keywords: ["/ifcMap", "Specify named module and header unit mappings to IFC files."]
99
---
1010
# `/ifcMap`
1111

12-
This switch tells the compiler where to find the [TOML](https://toml.io/en/) file that maps named modules and header units to their respective IFC (.ifc) files.
12+
This switch tells the compiler where to find the IFC reference map file, which maps references to named modules and header units to their corresponding IFC (`.ifc`) files.
1313

1414
## Syntax
1515

1616
> **`/ifcMap`** *`filename`*
1717
1818
## Remarks
1919

20-
The *`filename`* argument specifies a TOML (Tom's Obvious Minimal Language) file. The file can be relative to the compiler's working directory, or an absolute path.
21-
Multiple `/ifcMap` arguments can be provided to the compiler.
20+
The `*filename*` argument specifies the IFC reference map file. It can be relative to the compiler's working directory, or an absolute path.
2221

23-
The TOML file can contain a mix of `[[module]]` and `[[header-unit]]` references. Syntax errors or unrecognized table names result in compiler error `C7696` (TOML parse error).
22+
You can provide multiple `/ifcMap` arguments to the compiler.
2423

25-
### TOML for named modules
24+
The IFC reference map file format is a subset of the [TOML](https://toml.io/en/) file format. The IFC reference map file can contain a mix of `[[module]]` and `[[header-unit]]` references.
2625

27-
The format of the TOML file must adhere to the following specification for named modules:
26+
Syntax errors or unrecognized table names result in compiler error `C7696` (TOML parse error).
27+
28+
### Map named modules
29+
30+
The format of the IFC reference map file for named modules is:
2831

2932
```
3033
# Using literal strings
@@ -38,17 +41,17 @@ name = "N"
3841
ifc = "C:\\modules\\N.ifc"
3942
```
4043

41-
This TOML file maps the named modules `'M'` and `'N'` to their respective IFC files. The equivalent [`/reference'](module-reference.md) is:
44+
This IFC reference map file maps the named modules `'M'` and `'N'` to their respective IFC files. The equivalent [`/reference'](module-reference.md) is:
4245

4346
```cmd
4447
/reference M=C:\modules\M.ifc /reference N=C:\modules\N.ifc
4548
```
4649

4750
For more information about what types of module names are valid for the `name` field, see [`/reference remarks`](module-reference.md#remarks).
4851

49-
### TOML for header units
52+
### Map header units
5053

51-
The format of the TOML for header units is:
54+
The format of the IFC reference map file for header units is:
5255

5356
```
5457
# Using literal strings
@@ -70,13 +73,13 @@ name = ["angle", "algorithm"]
7073
ifc = "C:\\header-units\\algorithm.ifc"
7174
```
7275

73-
The equivalent [`/headerUnit`](headerunit.md) for the previous TOML is:
76+
This IFC reference map file maps `"my-utility.h"` to `C:\header-units\my-utility.h.ifc`, and `<vector>` to `C:\header-units\vector.ifc`, and so on. The equivalent [`/headerUnit`](headerunit.md) is:
7477

7578
```cmd
7679
/headerUnit:quote my-utility=C:\header-units\my-utility.h.ifc /headerUnit:angle vector=C:\header-units\vector.ifc /headerUnit:quote my-engine.h=C:\header-units\my-engine.h.ifc /headerUnit:angle algorithm=C:\header-units\algorithm.ifc
7780
```
7881

79-
When `[[header-unit]]` is specified in the TOML, the compiler implicitly enables [`/Zc:preprocessor`](zc-preprocessor.md), just as it's implicitly enabled when [`/headerUnit`](headerunit.md) is used. For more information about the behavior of the 'angle' and 'quote' lookup methods, see the [/headerUnit remarks](headerunit.md#remarks).
82+
When `[[header-unit]]` is specified in an IFC reference map file, the compiler implicitly enables [`/Zc:preprocessor`](zc-preprocessor.md), just as it's implicitly enabled when [`/headerUnit`](headerunit.md) is used. For more information about the behavior of the `angle` and `quote` lookup methods, see [/headerUnit remarks](headerunit.md#remarks).
8083

8184
## See also
8285

docs/cpp/if-else-statement-cpp.md

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
---
22
title: "if-else statement (C++)"
33
description: "Use if-else, if-else with initializer, and if-constexpr statements to control conditional branching."
4-
ms.date: 10/02/2020
4+
ms.date: 10/16/2023
55
f1_keywords: ["else_cpp", "if_cpp"]
66
helpviewer_keywords: ["if keyword [C++]", "else keyword [C++]"]
7-
ms.assetid: f8c45cde-6bce-42ae-81db-426b3dbd4caa
87
---
98
# if-else statement (C++)
109

11-
An if-else statement controls conditional branching. Statements in the *`if-branch`* are executed only if the *`condition`* evaluates to a non-zero value (or **`true`**). If the value of *`condition`* is nonzero, the following statement gets executed, and the statement following the optional **`else`** gets skipped. Otherwise, the following statement gets skipped, and if there's an **`else`** then the statement following the **`else`** gets executed.
10+
An if-else statement controls conditional branching. Statements in the *`if-branch`* are executed only if the *`condition`* evaluates to a nonzero value (or **`true`**). If the value of *`condition`* is nonzero, the following statement gets executed, and the statement following the optional **`else`** gets skipped. Otherwise, the following statement gets skipped, and if there's an **`else`** then the statement following the **`else`** gets executed.
1211

13-
*`condition`* expressions that evaluate to non-zero are:
12+
*`condition`* expressions that evaluate to nonzero are:
1413

1514
- **`true`**
1615
- a non-null pointer,
17-
- any non-zero arithmetic value, or
16+
- any nonzero arithmetic value, or
1817
- a class type that defines an unambiguous conversion to an arithmetic, boolean, or pointer type. (For information about conversions, see [Standard Conversions](../cpp/standard-conversions.md).)
1918

2019
## Syntax
@@ -69,52 +68,54 @@ This sample code shows several **`if`** statements in use, both with and without
6968

7069
using namespace std;
7170

72-
class C
73-
{
74-
public:
75-
void do_something(){}
76-
};
77-
void init(C){}
78-
bool is_true() { return true; }
79-
int x = 10;
80-
8171
int main()
8272
{
83-
if (is_true())
73+
int x = 10;
74+
75+
if (x < 11)
8476
{
85-
cout << "b is true!\n"; // executed
77+
cout << "x < 11 is true!\n"; // executed
8678
}
8779
else
8880
{
89-
cout << "b is false!\n";
81+
cout << "x < 11 is false!\n"; // not executed
9082
}
9183

9284
// no else statement
93-
if (x == 10)
85+
bool flag = false;
86+
if (flag == true)
9487
{
95-
x = 0;
88+
x = 100; // not executed
9689
}
9790

98-
C* c;
99-
init(c);
100-
if (c)
91+
int *p = new int(25);
92+
if (p)
10193
{
102-
c->do_something();
94+
cout << *p << "\n"; // outputs 25
10395
}
10496
else
10597
{
106-
cout << "c is null!\n";
98+
cout << "p is null!\n"; // executed if memory allocation fails
10799
}
108100
}
109101
```
110102

103+
Output:
104+
105+
```output
106+
x < 11 is true!
107+
25
108+
```
109+
111110
## <a name="if_with_init"></a> if statement with an initializer
112111

113-
Starting in C++17, an **`if`** statement may also contain an *`init-statement`* expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-statement. **Microsoft-specific**: This form is available starting in Visual Studio 2017 version 15.3, and requires at least the [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) compiler option.
112+
Starting in C++17, an **`if`** statement might also contain an *`init-statement`* expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-statement. **Microsoft-specific**: This form is available starting in Visual Studio 2017 version 15.3, and requires at least the [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) compiler option.
114113

115114
### Example
116115

117116
```cpp
117+
// Compile with /std:c++17
118+
118119
#include <iostream>
119120
#include <mutex>
120121
#include <map>
@@ -123,28 +124,27 @@ Starting in C++17, an **`if`** statement may also contain an *`init-statement`*
123124

124125
using namespace std;
125126

126-
map<int, string> m;
127+
map<int, string> m{ {1, "one"}, {2, "two"}, {10,"ten"} };
127128
mutex mx;
128-
bool shared_flag; // guarded by mx
129-
void unsafe_operation() {}
129+
bool shared_flag = true; // guarded by mx
130+
int getValue() { return 42; }
130131

131132
int main()
132133
{
133134

134135
if (auto it = m.find(10); it != m.end())
135136
{
136-
cout << it->second;
137-
return 0;
137+
cout << it->second << "\n";
138138
}
139139

140-
if (char buf[10]; fgets(buf, 10, stdin))
140+
if (int x = getValue(); x == 42)
141141
{
142-
m[0] += buf;
142+
cout << "x is 42\n";
143143
}
144144

145145
if (lock_guard<mutex> lock(mx); shared_flag)
146146
{
147-
unsafe_operation();
147+
cout << "setting shared_flag to false\n";
148148
shared_flag = false;
149149
}
150150

@@ -156,31 +156,62 @@ int main()
156156
}
157157
```
158158
159+
Output:
160+
161+
```Output
162+
ten
163+
x is 42
164+
setting shared_flag to false
165+
Error! Token must not be a keyword
166+
```
167+
159168
## <a name="if_constexpr"> if constexpr statements
160169

161170
Starting in C++17, you can use an **`if constexpr`** statement in function templates to make compile-time branching decisions without having to resort to multiple function overloads. **Microsoft-specific**: This form is available starting in Visual Studio 2017 version 15.3, and requires at least the [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) compiler option.
162171

163172
### Example
164173

165-
This example shows how you can write a single function that handles parameter unpacking. No zero-parameter overload is needed:
174+
This example shows how you can conditionally compile a template based on the type sent to it:
166175

167176
```cpp
168-
template <class T, class... Rest>
169-
void f(T&& t, Rest&&... r)
170-
{
171-
// handle t
172-
do_something(t);
177+
// Compile with /std:c++17
178+
#include <iostream>
173179

174-
// handle r conditionally
175-
if constexpr (sizeof...(r))
180+
template<typename T>
181+
auto Show(T t)
182+
{
183+
//if (std::is_pointer_v<T>) // Show(a) results in compiler error for return *t. Show(b) results in compiler error for return t.
184+
if constexpr (std::is_pointer_v<T>) // This statement goes away for Show(a)
176185
{
177-
f(r...);
186+
return *t;
178187
}
179188
else
180189
{
181-
g(r...);
190+
return t;
182191
}
183192
}
193+
194+
int main()
195+
{
196+
int a = 42;
197+
int* pB = &a;
198+
199+
std::cout << Show(a) << "\n"; // prints "42"
200+
std::cout << Show(pB) << "\n"; // prints "42"
201+
}
202+
```
203+
204+
The **`if constexpr`** statement is evaluated at compile time, and the compiler only generates code for the **`if`** branch that matches the type of the argument sent to the function template. If you comment out the **`if constexpr`** statement and uncomment the **`if`** statement, the compiler generates code for both branches. That means you get an error:
205+
- If you call `ShowValue(a);` you get an error on `return *t` because `t` isn't a pointer, even though the **`if`** statement is false and the code is never executed.
206+
- If you call `ShowValue(pB);` you get an error on `return t` because `t` is a pointer, even though the **`if`** statement is true and the code is never executed.
207+
208+
Using `if constexpr` solves this problem because only the statement that matches the type of the argument sent to the function template is compiled.
209+
210+
Output:
211+
212+
```output
213+
42
214+
42
184215
```
185216

186217
## See also

docs/error-messages/compiler-errors-2/compiler-error-c2534.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@ ms.assetid: 481f9f54-5b51-4aa0-8eea-218f10807705
1010

1111
'identifier' : constructor cannot return a value
1212

13-
A constructor cannot return a value or have a return type (not even a **`void`** return type).
14-
15-
This error may be fixed by removing the **`return`** statement from the constructor definition.
13+
A constructor cannot contain a **`return`** statement with an expression (even if the expression has type **`void`**). This differs from regular void-returning function where a return expression of type **`void`** is allowed. However, using the **`return`** statement without an expression is allowed for early returns in the constructor.
1614

1715
The following sample generates C2534:
1816

1917
```cpp
2018
// C2534.cpp
19+
// compile with: /c
20+
void void_func() {}
21+
2122
class A {
2223
public:
2324
int i;
24-
A() { return i; } // C2534
25+
A() {
26+
return i; // C2534
27+
return 123; // C2534
28+
return (void)0; // C2534
29+
return void_func(); // C2534
30+
31+
return; // OK
32+
}
2533
};
2634
```
35+
36+
The preceding errors may be fixed by removing the entire **`return`** statement or omitting the return expression if an early return is desired.

docs/intrinsics/sentinel-conversion-functions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: Sentinel floating-point conversion functions"
33
title: "Sentinel conversion functions"
4-
ms.date: 11/18/2021
4+
ms.date: 10/16/2023
55
f1_keywords: ["intrin/_cvt_dtoi_sent", "intrin/_cvt_dtoll_sent", "intrin/_cvt_dtoui_sent", "intrin/_cvt_dtoull_sent", "intrin/_cvt_ftoi_sent", "intrin/_cvt_ftoll_sent", "intrin/_cvt_ftoui_sent", "intrin/_cvt_ftoull_sent"]
66
helpviewer_keywords: ["_cvt_dtoi_sent", "_cvt_dtoll_sent", "_cvt_dtoui_sent", "_cvt_dtoull_sent", "_cvt_ftoi_sent", "_cvt_ftoll_sent", "_cvt_ftoui_sent", "_cvt_ftoull_sent"]
77
---
@@ -35,20 +35,20 @@ The integer-typed result of the conversion.
3535
3636
## Requirements
3737
38-
**Header**: \<intrin.h>
38+
**Header**: `<intrin.h>`
3939
4040
**Architecture**: x86, x64
4141
4242
## Remarks
4343
44-
These intrinsics are floating-point to integral type conversion functions that use a *sentinel* strategy: They return the result value farthest from zero as a proxy sentinel value for NaN. Any invalid conversion returns this sentinel value. The specific sentinel value returned depends on the result type.
44+
These intrinsics are floating-point to integral type conversion functions that use a *sentinel* strategy: They return the result value farthest from zero as a proxy sentinel value for `NaN`. Any invalid conversion returns this sentinel value. The specific sentinel value returned depends on the result type.
4545
4646
| Result type | Sentinel | *`<limits.h>`* constant |
4747
|--|--|
48-
| `int` | -2147483648 (0xFFFFFFFF) | `INT_MIN` |
48+
| `int` | -2147483648 (0x80000000) | `INT_MIN` |
4949
| `unsigned int` | 4294967295 (0xFFFFFFFF) | `UINT_MAX` |
50-
| `long long` | -9223372036854775808 (0xFFFFFFFF'FFFFFFFF) | `LLONG_MIN` |
51-
| `unsigned long long` | 18446744073709551615 (0xFFFFFFFF'FFFFFFFF) | `ULLONG_MAX` |
50+
| `long long` | -9223372036854775808 (0x8000000000000000) | `LLONG_MIN` |
51+
| `unsigned long long` | 18446744073709551615 (0xFFFFFFFFFFFFFFFF) | `ULLONG_MAX` |
5252
5353
The sentinel conversion intrinsics are available starting in Visual Studio 2019 version 16.10.
5454

0 commit comments

Comments
 (0)