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
Copy file name to clipboardExpand all lines: docs/build/cmake-presets-vs.md
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -25,18 +25,20 @@ Visual Studio supports version 2 or later for the *`CMakePresets.json`* and *`CM
25
25
26
26
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.
27
27
28
-
## <aname="enable-cmakepresets-json-integration"> Enable *`CMakePresets.json`* integration in Visual Studio 2019
28
+
## <aname="enable-cmakepresets-json-integration"> Enable *`CMakePresets.json`* integration in Visual Studio
29
29
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**:
31
31
32
-

32
+

33
33
34
34
> [!Important]
35
35
> Close and reopen the folder in Visual Studio to activate the integration.
36
36
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.
38
38
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
+

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.
40
42
41
43
In the table, "**Tools** > **Options** enabled" means **Use CMakePresets.json to drive CMake configure, build, and test** is selected in **Tools** > **Options** > **CMake** > **General**.
Copy file name to clipboardExpand all lines: docs/build/walkthrough-build-debug-wsl2.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Visual Studio defines a CMake project as a folder with a `CMakeLists.txt` file a
55
55
56
56
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**.
57
57
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).
59
59
60
60

61
61
@@ -102,7 +102,7 @@ You've now built and debugged a C++ app with WSL 2 and Visual Studio 2022.
102
102
103
103
## Advanced WSL 2 and CMake projects considerations
104
104
105
-
Visual Studio only provides native support forWSL 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 integrationin Visual Studio](cmake-presets-vs.md#-enable--cmakepresetsjson-integration-in-visual-studio-2019).
105
+
Visual Studio only provides native support forWSL 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 integrationin Visual Studio](cmake-presets-vs.md#-enable--cmakepresetsjson-integration-in-visual-studio).
106
106
107
107
If you're targeting a WSL 2 distribution and you don't want to use the WSL 2 toolset, thenin 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.
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
5
5
f1_keywords: ["C4146"]
6
6
helpviewer_keywords: ["C4146"]
7
-
ms.assetid: d6c31ab1-3120-40d5-8d80-32b5f7046e32
8
7
---
9
-
# Compiler Warning (level 2) C4146
8
+
# Compiler warning (level 2) C4146
10
9
11
-
unary minus operator applied to unsigned type, result still unsigned
10
+
> unary minus operator applied to unsigned type, result still unsigned
12
11
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.
14
13
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
16
15
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.
18
17
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:
20
19
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`**.
22
21
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.
24
23
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.
26
27
27
28
## Example
28
29
29
-
The following sample generates C4146:
30
+
The following sample demonstrates the unexpected behavior that can happen when the compiler generates warning C4146:
30
31
31
32
```cpp
32
33
// C4146.cpp
33
34
// compile with: /W2
34
-
#include<stdio.h>
35
+
#include<iostream>
35
36
36
37
voidcheck(int i)
37
38
{
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";
40
41
}
41
42
42
43
int main()
@@ -45,3 +46,11 @@ int main()
45
46
check(1);
46
47
}
47
48
```
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`.
Copy file name to clipboardExpand all lines: docs/overview/what-s-new-for-visual-cpp-in-visual-studio.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ Select Standard Library (STL) improvements are highlighted here. For a comprehen
81
81
82
82
### C++ AMP deprecated
83
83
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).
85
85
86
86
### IntelliSense improvements
87
87
@@ -127,4 +127,4 @@ We'd love to hear from you! You can [Report a Problem or Suggest a Feature](/vis
127
127
128
128
## Blogs
129
129
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