Skip to content

Repo sync for protected branch #4939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions docs/c-language/c-keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The C language uses the following keywords:
**`struct`**\
**`switch`**\
**`typedef`**\
**[`typeof`](typeof-c.md)**\
**[`typeof_unqual`](typeof-unqual-c.md)**\
**`union`**\
**`unsigned`**\
**`void`**\
Expand All @@ -67,12 +69,9 @@ The C language uses the following keywords:
:::column-end:::
:::row-end:::

<sup>1</sup> Keywords introduced in ISO C99.

<sup>2</sup> Keywords introduced in ISO C11.

<sup>a</sup> Starting in Visual Studio 2019 version 16.8, these keywords are supported in code compiled as C when the **`/std:c11`** or **`/std:c17`** compiler options are specified.

<sup>1</sup> Keywords introduced in ISO C99.\
<sup>2</sup> Keywords introduced in ISO C11.\
<sup>a</sup> Starting in Visual Studio 2019 version 16.8, these keywords are supported in code compiled as C when the **`/std:c11`** or **`/std:c17`** compiler options are specified.\
<sup>b</sup> Starting in Visual Studio 2019 version 16.8, these keywords are recognized but not supported by the compiler in code compiled as C when the **`/std:c11`** or **`/std:c17`** compiler options are specified.

You can't redefine keywords. However, you can specify text to replace keywords before compilation by using C [preprocessor directives](../preprocessor/preprocessor-directives.md).
Expand Down Expand Up @@ -105,6 +104,8 @@ The following keywords and special identifiers are recognized by the Microsoft C
:::column:::
**`__stdcall`**<sup>5</sup>\
**`__try`**<sup>5</sup>\
**[`__typeof__`](typeof-c.md)**\
**[`__typeof_unqual__`](typeof-unqual-c.md)**\
**`dllexport`**<sup>4</sup>\
**`dllimport`**<sup>4</sup>\
**`naked`**<sup>4</sup>\
Expand All @@ -113,17 +114,14 @@ The following keywords and special identifiers are recognized by the Microsoft C
:::column-end:::
:::row-end:::

<sup>3</sup> The **`__based`** keyword has limited uses for 32-bit and 64-bit target compilations.

<sup>4</sup> These are special identifiers when used with **`__declspec`**; their use in other contexts is unrestricted.

<sup>5</sup> For compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled.

<sup>3</sup> The **`__based`** keyword has limited uses for 32-bit and 64-bit target compilations.\
<sup>4</sup> These are special identifiers when used with **`__declspec`**; their use in other contexts is unrestricted.\
<sup>5</sup> For compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled.\
<sup>6</sup> If you don't include <assert.h>, the Microsoft Visual C compiler maps **`static_assert`** to the C11 **`_Static_assert`** keyword.

Microsoft extensions are enabled by default. To assist in creating portable code, you can disable Microsoft extensions by specifying the [/Za \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) option during compilation. When you use this option, some Microsoft-specific keywords are disabled.
Microsoft extensions are enabled by default. To help create portable code, you can disable Microsoft extensions by specifying the [/Za \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) option during compilation. When you use this option, some Microsoft-specific keywords are disabled.

When Microsoft extensions are enabled, you can use the keywords listed above in your programs. To conform to the language standard, most of these keywords are prefaced by a double underscore. The four exceptions, **`dllexport`**, **`dllimport`**, **`naked`**, and **`thread`**, are used only with **`__declspec`** and don't require a leading double underscore. For backward compatibility, single-underscore versions of the rest of the keywords are supported.
When Microsoft extensions are enabled, you can use the keywords listed above in your programs. To conform to the language standard, most of these keywords have a leading double underscore. The four exceptions, **`dllexport`**, **`dllimport`**, **`naked`**, and **`thread`**, are used only with **`__declspec`** and don't require a leading double underscore. For backward compatibility, single-underscore versions of the rest of the keywords are supported.

## See also

Expand Down
5 changes: 3 additions & 2 deletions docs/c-language/c-type-specifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ description: "Learn more about: C Type Specifiers"
title: "C Type Specifiers"
ms.date: "01/29/2018"
helpviewer_keywords: ["type specifiers, C", "specifiers, type"]
ms.assetid: fbe13441-04c3-4829-b047-06d374adc2b6
---
# C Type Specifiers

Expand Down Expand Up @@ -70,4 +69,6 @@ You can create more type specifiers with **`typedef`** declarations, as describe

## See also

[Declarations and Types](../c-language/declarations-and-types.md)
[Declarations and Types](../c-language/declarations-and-types.md)\
[`typeof, __typeof__` (C23)](typeof-c.md)\
[`typeof_unqual, __typeof_unqual__` (C23)](typeof-unqual-c.md)
4 changes: 4 additions & 0 deletions docs/c-language/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ items:
href: ../c-language/c-type-specifiers.md
- name: Data type specifiers and equivalents
href: ../c-language/data-type-specifiers-and-equivalents.md
- name: typeof
href: typeof-c.md
- name: typeof_unqual
href: typeof-unqual-c.md
- name: Type qualifiers
href: ../c-language/type-qualifiers.md
- name: Declarators and variable declarations
Expand Down
59 changes: 59 additions & 0 deletions docs/c-language/typeof-c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: "typeof, __typeof__ (C23)"
description: "Describes Microsoft Visual C23 typeof operator"
ms.date: 02/06/2024
helpviewer_keywords: ["typeof keyword [C]", "__typeof__ keyword [C]"]
---
# `typeof`, `__typeof__` (C23)

New in the C23 standard, the **`typeof`** operator is a unary operator that returns the type of an expression. It can be used in type declarations, type casts, type checks, and so on. It gets the type of a variable, function, or any C expression.

The **`__typeof__`** keyword is a Microsoft-specific extension that provides the same functionality as **`typeof`**. The `__typeof__` keyword differs from `typeof` only in that it's available when compiling for all versions of C (not just `/std:clatest`), and it may ease porting code between other compilers that support `__typeof__`.

### `typeof` syntax

```c
typeof(type)
typeof(constant-expression)
__typeof__(constant-expression)
```

### `typeof` example

This example uses `typeof()`, but the behavior is the same if you use `__typeof__`.

```c
// Compile with /std:clatest

#include <stdio.h>

double func()
{
3.14;
}

#define POINTER(T) typeof(T*)

int main()
{
auto a = func(); // the type for a (double) is inferred, but requires initialization at point of declaration
typeof(func()) b; // the type for b is double, but didn't have to be initialized at point of declaration

// Some declarations using typeof
POINTER(int) p1 = NULL; // p1 is int*

typeof(double(void))* pFunc = func; // pFunc is a pointer to a function that takes no arguments and returns a double
printf("pFunc() returns %f\n", pFunc());

return 0;
}
```

## Requirements

Requires Visual Studio 17.9 or later, or `cl.exe` version 19.39.33428 or later.
To use `typeof`, compile with [`/std:clatest`](../build/reference/std-specify-language-standard-version.md).

## See also

[`/std` (Specify Language Standard Version)](../build/reference/std-specify-language-standard-version.md)\
57 changes: 57 additions & 0 deletions docs/c-language/typeof-unqual-c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "typeof_unqual, __typeof_unqual__ (C23)"
description: "Describes Microsoft Visual C23 typeof_unqual operator"
ms.date: 02/06/2024
helpviewer_keywords: ["typeof_unqual keyword [C]", "__typeof_unqual__ keyword [C]"]
---
# `typeof_unqual`, `__typeof_unqual__` (C23)

New in the C23 standard, the **`typeof_unqual`** operator is a unary operator that returns the type of an expression after discarding qualifiers such as `const`, `volatile`, and `restrict`. It can be used in type declarations, type casts, type checks, and so on. It gets the type of a variable, function, or any C expression.

The **`__typeof_unqual__`** keyword is a Microsoft-specific extension that provides the same functionality as **`typeof_unqual`**. The **`__typeof_unqual__`** keyword differs from `typeof_unqual` only in that it's available when compiling for all versions of C (not just `/std:clatest`), and it may ease porting code between other compilers that support `__typeof_unqual__`.

### `typeof_unqual` syntax

```c
typeof_unqual(type)
typeof_unqual(constant-expression)
__typeof__unqual(constant-expression)
```

### `typeof_unqual` example

This example uses `typeof_unqual()`, but the behavior is the same if you use `__typeof_unqual__`.

```c
// Compile with /std:clatest and /experimental:c11atomics
#include <stdatomic.h>

// A function that takes an atomic int pointer, but uses a non-atomic copy of the value
void func(_Atomic(int) * pAtomic)
{
typeof_unqual(*pAtomic) local = *pAtomic;

// Use local non-atomic copy of value
}

int main()
{
int* const cpVar1 = 2;
typeof_unqual(cpVar1) pVar2 = 3;
pVar2 = 4; // no error because pi is not const. cpVar1 = 4 would be an error.

_Atomic(int)i = 42;
func(&i);

return 0;
}
```

## Requirements

Requires Visual Studio 17.9 or later, or `cl.exe` version 19.39.33428 or later.
To use `typeof_unqual`, compile with [`/std:clatest`](../build/reference/std-specify-language-standard-version.md).

## See also

[`/std` (Specify Language Standard Version)](../build/reference/std-specify-language-standard-version.md)\
52 changes: 46 additions & 6 deletions docs/overview/cpp-conformance-improvements.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
---
title: "C++ conformance improvements in Visual Studio 2022"
description: "Microsoft C++ in Visual Studio is improving standards conformance and fixing bugs regularly."
ms.date: 12/07/2023
ms.date: 2/6/2024
ms.service: "visual-cpp"
ms.subservice: "cpp-lang"
---
# C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2022

Microsoft C/C++ in Visual Studio (MSVC) makes conformance improvements and bug fixes in every release. This article lists the significant improvements by major release, then by version. To jump directly to the changes for a specific version, use **In this article** links, above.
Microsoft C/C++ in Visual Studio (MSVC) makes conformance improvements and bug fixes in every release. This article lists the significant improvements by major release, then by version. To jump directly to the changes for a specific version, use the **In this article** links.

This document lists the changes in Visual Studio 2022.

For a guide to the changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).\
For changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).\
For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md).\
For a complete list of previous conformance improvements, see [Visual C++ What's New 2003 through 2015](../porting/visual-cpp-what-s-new-2003-through-2015.md).
For changes in older versions, see [Visual C++ What's New 2003 through 2015](../porting/visual-cpp-what-s-new-2003-through-2015.md).

## <a name="improvements_179"></a> Conformance improvements in Visual Studio 2022 version 17.9

Visual Studio 2022 version 17.9 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.

For a broader summary of changes made to the Standard Template Library, see [STL Changelog VS 2022 17.9](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-179).

### `__VA_OPT__` is enabled as an extension under `/Zc:preprocessor`

`__VA_OPT__` was added to C++20 and C23. Previous to its addition, there wasn't a standard way to elide a comma in a variadic macro. To provide better backward compatibility, `__VA_OPT__` is enabled under the token based preprocessor `/Zc:preprocessor` across all language versions.

For example, this now compiles without error:

```cpp
#define LOG_WRAPPER(message, ...) WRITE_LOG(__LINE__, message __VA_OPT__(, __VA_ARGS__))

// Failed to build under /std:c11, now succeeds.
LOG_WRAPPER("Log message");
LOG_WRAPPER("Log message with %s", "argument")
```

### C23 language ###

For C23, the following are available when using the `/std:clatest` compiler switch:

[`typeof`](../c-language/typeof-c.md)\
[`typeof_unqual`](../c-language/typeof-unqual-c.md)

The following are available for all C language versions:

[`__typeof__`](../c-language/typeof-c.md)\
[`__typeof_unqual__`](../c-language/typeof-unqual-c.md)

### C++ Standard Library

**C++23 features**

- `formattable`, `range_format`, `format_kind`, and `set_debug_format()` as part of [P2286R8 Formatting Ranges](https://wg21.link/P2286R8)
- `<mdspan>` per [P0009R18](https://wg21.link/P0009R18) and subsequent wording changes that were applied to the C++23 Standard.
- `format()` pointers per [P2510R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2510r3.pdf).

## <a name="improvements_178"></a> Conformance improvements in Visual Studio 2022 version 17.8

Expand Down Expand Up @@ -315,7 +355,7 @@ bidi.cpp(8): warning C5255: unterminated bidirectional character encountered: 'U

### `from_chars()` `float` tiebreaker

Visual Studio 2022 version 17.2 fixes a bug in `<charconv>` `from_chars()` `float` tiebreaker rules that produced incorrect results. This bug affected decimal strings that were at the exact midpoint of consecutive `float` values, within a narrow range. (The smallest and largest affected values were `32768.009765625` and `131071.98828125`, respectively.) The tiebreaker rule wanted to round to "even," and "even" happened to be "down", but the implementation incorrectly rounded "up." (`double` was unaffected.) For more information and implementation details, see [microsoft/STL#2366](https://github.com/microsoft/STL/pull/2366).
Visual Studio 2022 version 17.2 fixes a bug in `<charconv>` `from_chars()` `float` tiebreaker rules that produced incorrect results. This bug affected decimal strings that were at the exact midpoint of consecutive `float` values, within a narrow range. (The smallest and largest affected values were `32768.009765625` and `131071.98828125`, respectively.) The tiebreaker rule wanted to round to "even", and "even" happened to be "down", but the implementation incorrectly rounded "up" (`double` was unaffected.) For more information and implementation details, see [microsoft/STL#2366](https://github.com/microsoft/STL/pull/2366).

This change affects runtime behavior in the specified range of cases:

Expand Down Expand Up @@ -483,7 +523,7 @@ int main(void)

### Error on a nondependent `static_assert`

In Visual Studio 2022 version 17.1 and later, if the expression associated with a `static_assert` isn't a dependent expression, the compiler evaluates the expression when it is parsed. If the expression evaluates to `false`, the compiler emits an error. Previously, if the `static_assert` was within the body of a function template (or within the body of a member function of a class template), the compiler wouldn't perform this analysis.
In Visual Studio 2022 version 17.1 and later, if the expression associated with a `static_assert` isn't a dependent expression, the compiler evaluates the expression when it's parsed. If the expression evaluates to `false`, the compiler emits an error. Previously, if the `static_assert` was within the body of a function template (or within the body of a member function of a class template), the compiler wouldn't perform this analysis.

This change is a source breaking change. It applies in any mode that implies **`/permissive-`** or **`/Zc:static_assert`**. This change in behavior can be disabled by using the **`/Zc:static_assert-`** compiler option.

Expand Down
Binary file added docs/overview/media/custom-cmake-option.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/overview/media/include-diagnostics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/overview/media/memory-layout-window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading