Skip to content

Commit fcfe198

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs-pr (branch live)
2 parents 6c2a153 + 4edc796 commit fcfe198

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

docs/build/cmake-presets-vs.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ Visual Studio supports version 2 or later for the *`CMakePresets.json`* and *`CM
2525

2626
CMake version 3.20 or later is required when you're invoking CMake with *`CMakePresets.json`* (version 2 or later) from the command line. However, Visual Studio reads and evaluates *`CMakePresets.json`* and *`CMakeUserPresets.json`* itself and doesn't invoke CMake directly with the `--preset` option. So, CMake version 3.20 or later isn't strictly required when you're building with *`CMakePresets.json`* inside Visual Studio. We recommend using CMake version 3.14 or later.
2727

28-
## <a name="enable-cmakepresets-json-integration"> Enable *`CMakePresets.json`* integration in Visual Studio 2019
28+
## <a name="enable-cmakepresets-json-integration"> Enable *`CMakePresets.json`* integration in Visual Studio
2929

30-
*`CMakePresets.json`* integration isn't enabled by default in Visual Studio 2019. You can enable it for all CMake projects in **Tools** > **Options** > **CMake** > **General**:
30+
*`CMakePresets.json`* integration isn't enabled by default in Visual Studio. You can enable it in **Tools** > **Options** > **CMake** > **General**:
3131

32-
![Screenshot showing the checkbox to enable CMakePresets.json on the CMake General page of the Tools Options dialog.](./media/enable-cmakepresets.png)
32+
![Screenshot showing the checkbox to enable CMakePresets.json on the CMake General page of the Tools Options dialog in Visual Studio 2022 version 17.1.](./media/enable-cmakepresets-new.png)
3333

3434
> [!Important]
3535
> Close and reopen the folder in Visual Studio to activate the integration.
3636
37-
If you don't want to enable *`CMakePresets.json`* integration for all CMake projects, you can enable *`CMakePresets.json`* integration for a single CMake project by adding a *`CMakePresets.json`* file to the root of the open folder. Close and reopen the folder in Visual Studio to activate the integration.
37+
In Visual Studio 2022 version 17.0 and Visual Studio 2019, **Tools** > **Options** > **CMake** > **General** has a single option to enable *`CMakePresets.json`* integration.
3838

39-
The following table indicates when *`CMakePresets.json`* is used instead of *`CMakeSettings.json`* to drive CMake configuration and build. If no configuration file is present, default Configure Presets are used.
39+
![Screenshot showing the checkbox to enable CMakePresets.json on the CMake General page of the Tools Options dialog in Visual Studio 2019.](./media/enable-cmakepresets.png)
40+
41+
The following table indicates when *`CMakePresets.json`* is used instead of *`CMakeSettings.json`* to drive CMake configuration and build in Visual Studio 2022 version 17.0 and Visual Studio 2019. If no configuration file is present, default Configure Presets are used.
4042

4143
In the table, "**Tools** > **Options** enabled" means **Use CMakePresets.json to drive CMake configure, build, and test** is selected in **Tools** > **Options** > **CMake** > **General**.
4244

61 KB
Loading

docs/build/walkthrough-build-debug-wsl2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Visual Studio defines a CMake project as a folder with a `CMakeLists.txt` file a
5555
5656
4. In the **Search for templates** textbox, type "cmake". Choose the **CMake Project** type and select **Next**. Give the project a name and location, and then select **Create**.
5757
58-
5. Enable Visual Studio’s CMake Presets integration. Select **Tools** > **Options** > **CMake** > **General**. Select **Prefer using CMake Presets for configure, build, and test**, then select **OK**. Instead, you could have added a `CMakePresets.json` file to the root of the project. For more information, see [Enable CMake Presets integration](cmake-presets-vs.md#-enable--cmakepresetsjson-integration-in-visual-studio-2019).
58+
5. Enable Visual Studio’s CMake Presets integration. Select **Tools** > **Options** > **CMake** > **General**. Select **Prefer using CMake Presets for configure, build, and test**, then select **OK**. Instead, you could have added a `CMakePresets.json` file to the root of the project. For more information, see [Enable CMake Presets integration](cmake-presets-vs.md#-enable--cmakepresetsjson-integration-in-visual-studio).
5959
6060
![Screenshot of CMake general options screen with Prefer using CMake Presets for configure, build, and test highlighted and selected](media/cmake-general-prefer-cmake-presets.png)
6161
@@ -102,7 +102,7 @@ You've now built and debugged a C++ app with WSL 2 and Visual Studio 2022.
102102

103103
## Advanced WSL 2 and CMake projects considerations
104104

105-
Visual Studio only provides native support for WSL 2 for CMake projects that use `CMakePresets.json` as the active configuration file. To migrate from `CMakeSettings.json` to `CMakePresets.json`, see [Enable CMake Presets integration in Visual Studio](cmake-presets-vs.md#-enable--cmakepresetsjson-integration-in-visual-studio-2019).
105+
Visual Studio only provides native support for WSL 2 for CMake projects that use `CMakePresets.json` as the active configuration file. To migrate from `CMakeSettings.json` to `CMakePresets.json`, see [Enable CMake Presets integration in Visual Studio](cmake-presets-vs.md#-enable--cmakepresetsjson-integration-in-visual-studio).
106106

107107
If you're targeting a WSL 2 distribution and you don't want to use the WSL 2 toolset, then in the Visual Studio Remote Settings vendor map in `CMakePresets.json`, set **forceWSL1Toolset** to **true** . See [Visual Studio Remote Settings vendor map](cmake-presets-json-reference.md#visual-studio-remote-settings-vendor-map) for details.
108108

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 2) C4146"
3-
title: "Compiler Warning (level 2) C4146"
4-
ms.date: "11/04/2016"
2+
description: "Learn more about: Compiler warning (level 2) C4146"
3+
title: "Compiler warning (level 2) C4146"
4+
ms.date: 11/18/2021
55
f1_keywords: ["C4146"]
66
helpviewer_keywords: ["C4146"]
7-
ms.assetid: d6c31ab1-3120-40d5-8d80-32b5f7046e32
87
---
9-
# Compiler Warning (level 2) C4146
8+
# Compiler warning (level 2) C4146
109

11-
unary minus operator applied to unsigned type, result still unsigned
10+
> unary minus operator applied to unsigned type, result still unsigned
1211
13-
Unsigned types can hold only non-negative values, so unary minus (negation) does not usually make sense when applied to an unsigned type. Both the operand and the result are non-negative.
12+
Unsigned types can hold only non-negative values, so unary minus (negation) usually doesn't make sense when applied to an unsigned type. Both the operand and the result are non-negative.
1413

15-
Practically, this occurs when the programmer is trying to express the minimum integer value, which is -2147483648. This value cannot be written as -2147483648 because the expression is processed in two stages:
14+
## Remarks
1615

17-
1. The number 2147483648 is evaluated. Because it is greater than the maximum integer value of 2147483647, the type of 2147483648 is not [int](../../c-language/integer-types.md), but **`unsigned int`**.
16+
When you express a negative integer literal, the **`-`** in front of the value is parsed as a [unary negation](../../cpp/unary-plus-and-negation-operators-plus-and.md) operator. The compiler applies the operator after it parses the numeric value. If the numeric value fits in the range of an unsigned integer type, but not the corresponding signed integer type, the compiler interprets the value as unsigned. An unsigned value is unchanged by the unary negation operator.
1817

19-
1. Unary minus is applied to the value, with an unsigned result, which also happens to be 2147483648.
18+
This warning often occurs when you try to express the minimum **`int`** value, -2147483648, or the minimum **`long long`** value, -9223372036854775808. These values can't be written as -2147483648 or -9223372036854775808ll, respectively. That's because the compiler processes the expression in two stages: first, it parses the numeric value, then it applies the negation operator. For example, when the compiler parses -2147483648, it follows these steps:
2019

21-
The unsigned type of the result can cause unexpected behavior. If the result is used in a comparison, then an unsigned comparison might be used, for example, when the other operand is an **`int`**. This explains why the example program below prints just one line.
20+
1. The number 2147483648 is evaluated. Because it's greater than the maximum **`int`** value of 2147483647, but still fits in an **`unsigned int`**, the type of 2147483648 is **`unsigned int`**.
2221

23-
The expected second line, `1 is greater than the most negative int`, is not printed because `((unsigned int)1) > 2147483648` is false.
22+
1. Unary minus is applied to the unsigned value, with an unsigned result, which also happens to be 2147483648.
2423

25-
You can avoid C4146 by using INT_MIN from limits.h, which has the type **`signed int`**.
24+
The unsigned type of the result can cause unexpected behavior. If the result is used in a comparison, then an unsigned comparison might be used, for example, when the other operand is an **`int`**.
25+
26+
You can avoid C4146 by using `INT_MIN` or `LLONG_MIN` from *`<limits.h>`* or the C++ equivalent, *`<climits>`*. These values have signed types.
2627

2728
## Example
2829

29-
The following sample generates C4146:
30+
The following sample demonstrates the unexpected behavior that can happen when the compiler generates warning C4146:
3031

3132
```cpp
3233
// C4146.cpp
3334
// compile with: /W2
34-
#include <stdio.h>
35+
#include <iostream>
3536

3637
void check(int i)
3738
{
38-
if (i > -2147483648) // C4146
39-
printf_s("%d is greater than the most negative int\n", i);
39+
if (i > -9223372036854775808ll) // C4146
40+
std::cout << i << " is greater than the most negative long long int.\n";
4041
}
4142

4243
int main()
@@ -45,3 +46,11 @@ int main()
4546
check(1);
4647
}
4748
```
49+
50+
In this example, the compiler considers -9223372036854775808ll unsigned even though the literal has an `ll` suffix and the negation operator is applied. To make the `<` comparison, the compiler silently promotes signed `i` to `unsigned long long int`. The expected second line, `1 is greater than the most negative long long int`, isn't printed because `((unsigned long long int)1) > 9223372036854775808ull` is false.
51+
52+
To fix the example, include *`<climits>`* and change -9223372036854775808ll to `LLONG_MIN`.
53+
54+
## See also
55+
56+
[Unary negation operator (-)](../../cpp/unary-plus-and-negation-operators-plus-and.md)

docs/overview/what-s-new-for-visual-cpp-in-visual-studio.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Select Standard Library (STL) improvements are highlighted here. For a comprehen
8181

8282
### C++ AMP deprecated
8383

84-
- C++ AMP headers are now deprecated. Including `<amp.h>` in a C++ project generates build errors. To silence the errors, define `_SILENCE_AMP_DEPRECATION_WARNINGS`. For more information, see [our AMP Deprecation links](https://aka.ms/amp_deprecate).
84+
- C++ AMP headers are now deprecated. Including `<amp.h>` in a C++ project generates build errors. To silence the errors, define `_SILENCE_AMP_DEPRECATION_WARNINGS`. For more information, see [our AMP Deprecation links](/cpp/parallel/amp/cpp-amp-overview).
8585

8686
### IntelliSense improvements
8787

@@ -127,4 +127,4 @@ We'd love to hear from you! You can [Report a Problem or Suggest a Feature](/vis
127127

128128
## Blogs
129129

130-
Take advantage of the insights and recommendations available in the [Microsoft Developer Blogs](https://devblogs.microsoft.com/) site. They'll keep you up to date on all new releases. The blogs include deep dive posts on a broad range of features. You'll find the [C++ Team Blog](https://devblogs.microsoft.com/cppblog) and the [Visual Studio Blog](https://devblogs.microsoft.com/visualstudio) of particular interest.
130+
Take advantage of the insights and recommendations available in the [Microsoft Developer Blogs](https://devblogs.microsoft.com/) site. They'll keep you up to date on all new releases. The blogs include deep dive posts on a broad range of features. You'll find the [C++ Team Blog](https://devblogs.microsoft.com/cppblog) and the [Visual Studio Blog](https://devblogs.microsoft.com/visualstudio) of particular interest.

0 commit comments

Comments
 (0)