Skip to content

Commit 102b581

Browse files
author
Colin Robertson
authored
Move code-quality C++ articles from visualstudio repo to cpp repo (#2683)
* Move code-analysis from VS to cpp * Fix build warnings and broken links * Fix more build issues * Fix some broken links * Fix folder name * Repo quality fixes. * Fix missing H1 * Move code-analysis from VS to cpp. Fixes build warnings and broken links and makes repo quality fixes.
1 parent 2e0d4fb commit 102b581

File tree

422 files changed

+18227
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+18227
-33
lines changed

docs/build/clang-support-cmake.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ You can specify another location by setting the **CMAKE_C_COMPILER** and **CMAKE
6868

6969
For Windows configurations, CMake by default invokes Clang in [clang-cl](https://llvm.org/devmtg/2014-04/PDFs/Talks/clang-cl.pdf) mode and links with the Microsoft implementation of the Standard Library. By default, **clang-cl.exe** is located in `C:\Program Files (x86)\Microsoft Visual Studio\2019\Common7\IDE\CommonExtensions\Microsoft\Llvm\bin`.
7070

71-
You can modify these values in **CMake Settings** under **CMake variables and cache**. Click **Show advanced variables**. Scroll down to find **CMAKE_CXX_COMPILER**, then click the **Browse** button to specify a different compiler path.
71+
You can modify these values in **CMake Settings** under **CMake variables and cache**. Click **Show advanced variables**. Scroll down to find **CMAKE_CXX_COMPILER**, then click the **Browse** button to specify a different compiler path.
7272

7373
## Edit, build, and debug
7474

docs/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Visual Studio includes C++ compilers, linkers, and other tools that you can use
1010

1111
## Use a 64-bit hosted developer command prompt shortcut
1212

13-
To access these command prompts on Windows 10, on the **Start** menu, open the folder for your version of Visual Studio, for example **Visual Studio 2019**, and then choose one of the x64 native or cross-tool developer command prompts.
13+
To access these command prompts on Windows 10, on the **Start** menu, open the folder for your version of Visual Studio, for example **Visual Studio 2019**, and then choose one of the x64 native or cross-tool developer command prompts.
1414

1515
![x64 Native Tools Command Prompt](media/x64-native-tools-command-prompt.png "x64 Native Tools in Start Menu")
1616

docs/build/reference/analyze-code-analysis.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Detailed analyzer results are written as XML to the file that is specified by *f
2828
Turns off analyzer output to the **Output** window.
2929

3030
**/analyze:stacksize** *number*\
31-
The *number* parameter that is used with this option specifies the size, in bytes, of the stack frame for which warning [C6262](/visualstudio/code-quality/c6262) is generated. The space before *number* is optional. If this parameter isn't specified, the stack frame size is 16KB by default.
31+
The *number* parameter that is used with this option specifies the size, in bytes, of the stack frame for which warning [C6262](/cpp/code-quality/c6262) is generated. The space before *number* is optional. If this parameter isn't specified, the stack frame size is 16KB by default.
3232

3333
**/analyze:max_paths** *number*\
3434
The *number* parameter that is used with this option specifies the maximum number of code paths to be analyzed. If this parameter isn't specified, the number is 256 by default. Larger values cause more thorough checking, but the analysis might take longer.
@@ -58,14 +58,14 @@ Enables the specified PREfast plugin as part of code analysis runs.
5858

5959
::: moniker range="<=vs-2017"
6060

61-
LocalEspC.dll is the plugin that implements concurrency-related code analysis checks in the range of C261XX warnings. For example, [C26100](/visualstudio/code-quality/c26100), [C26101](/visualstudio/code-quality/c26101), ..., [C26167](/visualstudio/code-quality/c26167).
61+
LocalEspC.dll is the plugin that implements concurrency-related code analysis checks in the range of C261XX warnings. For example, [C26100](/cpp/code-quality/c26100), [C26101](/cpp/code-quality/c26101), ..., [C26167](/cpp/code-quality/c26167).
6262

6363
To run LocalEspC.dll, use this compiler option: **/analyze:plugin LocalEspC.dll**
6464

6565
::: moniker-end
6666
::: moniker range=">=vs-2019"
6767

68-
ConcurrencyCheck.dll implements concurrency-related code analysis checks in the range of C261XX warnings. For example, [C26100](/visualstudio/code-quality/c26100), [C26101](/visualstudio/code-quality/c26101), ..., [C26167](/visualstudio/code-quality/c26167).
68+
ConcurrencyCheck.dll implements concurrency-related code analysis checks in the range of C261XX warnings. For example, [C26100](/cpp/code-quality/c26100), [C26101](/cpp/code-quality/c26101), ..., [C26167](/cpp/code-quality/c26167).
6969

7070
To run ConcurrencyCheck.dll, first run this command from a developer command prompt:
7171

@@ -87,7 +87,7 @@ Then use this compiler option: **/analyze:plugin EspXEngine.dll**.
8787

8888
## Remarks
8989

90-
For more information, see [Code analysis for C/C++ overview](/visualstudio/code-quality/code-analysis-for-c-cpp-overview) and [Code analysis for C/C++ warnings](/visualstudio/code-quality/code-analysis-for-c-cpp-warnings).
90+
For more information, see [Code analysis for C/C++ overview](/cpp/code-quality/code-analysis-for-c-cpp-overview) and [Code analysis for C/C++ warnings](/cpp/code-quality/code-analysis-for-c-cpp-warnings).
9191

9292
### To set this compiler option in the Visual Studio development environment
9393

docs/build/reference/profile-performance-tools-profiler.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Produces an output file that can be used with the Performance Tools profiler.
2929

3030
/PROFILE causes the linker to generate a relocation section in the program image. A relocation section allows the profiler to transform the program image to get profile data.
3131

32-
**/PROFILE** is only available only in Enterprise (team development) versions. For more information on PREfast, see [Code Analysis for C/C++ Overview](/visualstudio/code-quality/code-analysis-for-c-cpp-overview).
32+
**/PROFILE** is only available only in Enterprise (team development) versions. For more information on PREfast, see [Code Analysis for C/C++ Overview](/cpp/code-quality/code-analysis-for-c-cpp-overview).
3333

3434
### To set this linker option in the Visual Studio development environment
3535

docs/build/reference/resource-files-cpp.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.assetid: 338a4a0f-0c62-4ef1-a34f-5d86262d93a4
88

99
Resources are interface elements that provide information to the user. Bitmaps, icons, toolbars, and cursors are all resources. Some resources can perform an action such as selecting from a menu or entering data in dialog box.
1010

11-
For more information, see [Working with Resources](../../windows/working-with-resource-files.md).
11+
For more information, see [Working with Resources](../../windows/working-with-resource-files.md).
1212

1313
|File name|Directory location|Solution Explorer location|Description|
1414
|---------------|------------------------|--------------------------------|-----------------|

docs/c-runtime-library/sal-annotations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.assetid: 81893638-010c-41a0-9cb3-666fe360f3e0
88

99
If you examine the library header files, you may notice some unusual annotations, for example, `_In_z` and `_Out_z_cap_(_Size)`. These are examples of the Microsoft source-code annotation language (SAL), which provides a set of annotations to describe how a function uses its parameters, for example, the assumptions it makes about them and the guarantees it makes on finishing. The header file \<sal.h> defines the annotations.
1010

11-
For more information about using SAL annotations in Visual Studio, see [Using SAL Annotations to Reduce C/C++ Code Defects](/visualstudio/code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects).
11+
For more information about using SAL annotations in Visual Studio, see [Using SAL Annotations to Reduce C/C++ Code Defects](/cpp/code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects).
1212

1313
## See also
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Annotating function behavior
3+
ms.date: 11/04/2016
4+
ms.topic: "conceptual"
5+
f1_keywords:
6+
- "_On_failure_"
7+
- "_Return_type_success_"
8+
- "_Always_"
9+
- "_Maybe_raises_SEH_exception_"
10+
- "_Raises_SEH_exception_"
11+
- "_Called_from_function_class_"
12+
- "_Function_class_"
13+
- "_Must_inspect_result_"
14+
- "_Success_"
15+
- "_Check_return_"
16+
- "_Use_decl_annotations_"
17+
ms.assetid: c0aa268d-6fa3-4ced-a8c6-f7652b152e61
18+
---
19+
# Annotating function behavior
20+
21+
In addition to annotating [function parameters and return values](../code-quality/annotating-function-parameters-and-return-values.md), you can annotate properties of the whole function.
22+
23+
## Function annotations
24+
25+
The following annotations apply to the function as a whole and describe how it behaves or what it expects to be true.
26+
27+
|Annotation|Description|
28+
|----------------|-----------------|
29+
|`_Called_from_function_class_(name)`|Not intended to stand alone; instead, it is a predicate to be used with the `_When_` annotation. For more information, see [Specifying When and Where an Annotation Applies](../code-quality/specifying-when-and-where-an-annotation-applies.md).<br /><br /> The `name` parameter is an arbitrary string that also appears in a `_Function_class_` annotation in the declaration of some functions. `_Called_from_function_class_` returns nonzero if the function that is currently being analyzed is annotated by using `_Function_class_` that has the same value of `name`; otherwise, it returns zero.|
30+
|`_Check_return_`|Annotates a return value and states that the caller should inspect it. The checker reports an error if the function is called in a void context.|
31+
|`_Function_class_(name)`|The `name` parameter is an arbitrary string that is designated by the user. It exists in a namespace that is distinct from other namespaces. A function, function pointer, or—most usefully—a function pointer type may be designated as belonging to one or more function classes.|
32+
|`_Raises_SEH_exception_`|Annotates a function that always raises a structured exception handler (SEH) exception, subject to `_When_` and `_On_failure_` conditions. For more information, see [Specifying When and Where an Annotation Applies](../code-quality/specifying-when-and-where-an-annotation-applies.md).|
33+
|`_Maybe_raises_SEH_exception_`|Annotates a function that may optionally raise an SEH exception, subject to `_When_` and `_On_failure_` conditions.|
34+
|`_Must_inspect_result_`|Annotates any output value, including the return value, parameters, and globals. The analyzer reports an error if the value in the annotated object is not subsequently inspected. "Inspection" includes whether it is used in a conditional expression, is assigned to an output parameter or global, or is passed as a parameter. For return values, `_Must_inspect_result_` implies `_Check_return_`.|
35+
|`_Use_decl_annotations_`|May be used on a function definition (also known as a function body) in place of the list of annotations in the header. When `_Use_decl_annotations_` is used, the annotations that appear on an in-scope header for the same function are used as if they are also present in the definition that has the `_Use_decl_annotations_` annotation.|
36+
37+
## Success/failure annotations
38+
39+
A function can fail, and when it does, its results may be incomplete or differ from the results when the function succeeds. The annotations in the following list provide ways to express the failure behavior. To use these annotations, you must enable them to determine success; therefore, a `_Success_` annotation is required. Notice that `NTSTATUS` and `HRESULT` already have a `_Success_` annotation built into them; however, if you specify your own `_Success_` annotation on `NTSTATUS` or `HRESULT`, it overrides the built-in annotation.
40+
41+
|Annotation|Description|
42+
|----------------|-----------------|
43+
|`_Always_(anno_list)`|Equivalent to `anno_list _On_failure_(anno_list)`; that is, the annotations in `anno_list` apply whether or not the function succeeds.|
44+
|`_On_failure_(anno_list)`|To be used only when `_Success_` is also used to annotate the function—either explicitly, or implicitly through `_Return_type_success_` on a typedef. When the `_On_failure_` annotation is present on a function parameter or return value, each annotation in `anno_list` (anno) behaves as if it were coded as `_When_(!expr, anno)`, where `expr` is the parameter to the required `_Success_` annotation. This means that the implied application of `_Success_` to all post-conditions does not apply for `_On_failure_`.|
45+
|`_Return_type_success_(expr)`|May be applied to a typedef. Indicates that all functions that return that type and do not explicitly have `_Success_` are annotated as if they had `_Success_(expr)`. `_Return_type_success_` cannot be used on a function or a function pointer typedef.|
46+
|`_Success_(expr)`|`expr` is an expression that yields an rvalue. When the `_Success_` annotation is present on a function declaration or definition, each annotation (`anno`) on the function and in post-condition behaves as if it were coded as `_When_(expr, anno)`. The `_Success_` annotation may be used only on a function, not on its parameters or return type. There can be at most one `_Success_` annotation on a function, and it cannot be in any `_When_`, `_At_`, or `_Group_`. For more information, see [Specifying When and Where an Annotation Applies](../code-quality/specifying-when-and-where-an-annotation-applies.md).|
47+
48+
## See also
49+
50+
- [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md)
51+
- [Understanding SAL](../code-quality/understanding-sal.md)
52+
- [Annotating Function Parameters and Return Values](../code-quality/annotating-function-parameters-and-return-values.md)
53+
- [Annotating Structs and Classes](../code-quality/annotating-structs-and-classes.md)
54+
- [Annotating Locking Behavior](../code-quality/annotating-locking-behavior.md)
55+
- [Specifying When and Where an Annotation Applies](../code-quality/specifying-when-and-where-an-annotation-applies.md)
56+
- [Intrinsic Functions](../code-quality/intrinsic-functions.md)
57+
- [Best Practices and Examples](../code-quality/best-practices-and-examples-sal.md)

0 commit comments

Comments
 (0)