Skip to content

Commit dfc14ff

Browse files
Merge pull request #4939 from MicrosoftDocs/main638434461435986055sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 177b80c + 8e4b974 commit dfc14ff

10 files changed

+208
-25
lines changed

docs/c-language/c-keywords.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ The C language uses the following keywords:
4747
**`struct`**\
4848
**`switch`**\
4949
**`typedef`**\
50+
**[`typeof`](typeof-c.md)**\
51+
**[`typeof_unqual`](typeof-unqual-c.md)**\
5052
**`union`**\
5153
**`unsigned`**\
5254
**`void`**\
@@ -67,12 +69,9 @@ The C language uses the following keywords:
6769
:::column-end:::
6870
:::row-end:::
6971

70-
<sup>1</sup> Keywords introduced in ISO C99.
71-
72-
<sup>2</sup> Keywords introduced in ISO C11.
73-
74-
<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.
75-
72+
<sup>1</sup> Keywords introduced in ISO C99.\
73+
<sup>2</sup> Keywords introduced in ISO C11.\
74+
<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.\
7675
<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.
7776

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

116-
<sup>3</sup> The **`__based`** keyword has limited uses for 32-bit and 64-bit target compilations.
117-
118-
<sup>4</sup> These are special identifiers when used with **`__declspec`**; their use in other contexts is unrestricted.
119-
120-
<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.
121-
117+
<sup>3</sup> The **`__based`** keyword has limited uses for 32-bit and 64-bit target compilations.\
118+
<sup>4</sup> These are special identifiers when used with **`__declspec`**; their use in other contexts is unrestricted.\
119+
<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.\
122120
<sup>6</sup> If you don't include <assert.h>, the Microsoft Visual C compiler maps **`static_assert`** to the C11 **`_Static_assert`** keyword.
123121

124-
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.
122+
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.
125123

126-
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.
124+
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.
127125

128126
## See also
129127

docs/c-language/c-type-specifiers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: "Learn more about: C Type Specifiers"
33
title: "C Type Specifiers"
44
ms.date: "01/29/2018"
55
helpviewer_keywords: ["type specifiers, C", "specifiers, type"]
6-
ms.assetid: fbe13441-04c3-4829-b047-06d374adc2b6
76
---
87
# C Type Specifiers
98

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

7170
## See also
7271

73-
[Declarations and Types](../c-language/declarations-and-types.md)
72+
[Declarations and Types](../c-language/declarations-and-types.md)\
73+
[`typeof, __typeof__` (C23)](typeof-c.md)\
74+
[`typeof_unqual, __typeof_unqual__` (C23)](typeof-unqual-c.md)

docs/c-language/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ items:
171171
href: ../c-language/c-type-specifiers.md
172172
- name: Data type specifiers and equivalents
173173
href: ../c-language/data-type-specifiers-and-equivalents.md
174+
- name: typeof
175+
href: typeof-c.md
176+
- name: typeof_unqual
177+
href: typeof-unqual-c.md
174178
- name: Type qualifiers
175179
href: ../c-language/type-qualifiers.md
176180
- name: Declarators and variable declarations

docs/c-language/typeof-c.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "typeof, __typeof__ (C23)"
3+
description: "Describes Microsoft Visual C23 typeof operator"
4+
ms.date: 02/06/2024
5+
helpviewer_keywords: ["typeof keyword [C]", "__typeof__ keyword [C]"]
6+
---
7+
# `typeof`, `__typeof__` (C23)
8+
9+
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.
10+
11+
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__`.
12+
13+
### `typeof` syntax
14+
15+
```c
16+
typeof(type)
17+
typeof(constant-expression)
18+
__typeof__(constant-expression)
19+
```
20+
21+
### `typeof` example
22+
23+
This example uses `typeof()`, but the behavior is the same if you use `__typeof__`.
24+
25+
```c
26+
// Compile with /std:clatest
27+
28+
#include <stdio.h>
29+
30+
double func()
31+
{
32+
3.14;
33+
}
34+
35+
#define POINTER(T) typeof(T*)
36+
37+
int main()
38+
{
39+
auto a = func(); // the type for a (double) is inferred, but requires initialization at point of declaration
40+
typeof(func()) b; // the type for b is double, but didn't have to be initialized at point of declaration
41+
42+
// Some declarations using typeof
43+
POINTER(int) p1 = NULL; // p1 is int*
44+
45+
typeof(double(void))* pFunc = func; // pFunc is a pointer to a function that takes no arguments and returns a double
46+
printf("pFunc() returns %f\n", pFunc());
47+
48+
return 0;
49+
}
50+
```
51+
52+
## Requirements
53+
54+
Requires Visual Studio 17.9 or later, or `cl.exe` version 19.39.33428 or later.
55+
To use `typeof`, compile with [`/std:clatest`](../build/reference/std-specify-language-standard-version.md).
56+
57+
## See also
58+
59+
[`/std` (Specify Language Standard Version)](../build/reference/std-specify-language-standard-version.md)\

docs/c-language/typeof-unqual-c.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "typeof_unqual, __typeof_unqual__ (C23)"
3+
description: "Describes Microsoft Visual C23 typeof_unqual operator"
4+
ms.date: 02/06/2024
5+
helpviewer_keywords: ["typeof_unqual keyword [C]", "__typeof_unqual__ keyword [C]"]
6+
---
7+
# `typeof_unqual`, `__typeof_unqual__` (C23)
8+
9+
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.
10+
11+
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__`.
12+
13+
### `typeof_unqual` syntax
14+
15+
```c
16+
typeof_unqual(type)
17+
typeof_unqual(constant-expression)
18+
__typeof__unqual(constant-expression)
19+
```
20+
21+
### `typeof_unqual` example
22+
23+
This example uses `typeof_unqual()`, but the behavior is the same if you use `__typeof_unqual__`.
24+
25+
```c
26+
// Compile with /std:clatest and /experimental:c11atomics
27+
#include <stdatomic.h>
28+
29+
// A function that takes an atomic int pointer, but uses a non-atomic copy of the value
30+
void func(_Atomic(int) * pAtomic)
31+
{
32+
typeof_unqual(*pAtomic) local = *pAtomic;
33+
34+
// Use local non-atomic copy of value
35+
}
36+
37+
int main()
38+
{
39+
int* const cpVar1 = 2;
40+
typeof_unqual(cpVar1) pVar2 = 3;
41+
pVar2 = 4; // no error because pi is not const. cpVar1 = 4 would be an error.
42+
43+
_Atomic(int)i = 42;
44+
func(&i);
45+
46+
return 0;
47+
}
48+
```
49+
50+
## Requirements
51+
52+
Requires Visual Studio 17.9 or later, or `cl.exe` version 19.39.33428 or later.
53+
To use `typeof_unqual`, compile with [`/std:clatest`](../build/reference/std-specify-language-standard-version.md).
54+
55+
## See also
56+
57+
[`/std` (Specify Language Standard Version)](../build/reference/std-specify-language-standard-version.md)\

docs/overview/cpp-conformance-improvements.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,59 @@
11
---
22
title: "C++ conformance improvements in Visual Studio 2022"
33
description: "Microsoft C++ in Visual Studio is improving standards conformance and fixing bugs regularly."
4-
ms.date: 12/07/2023
4+
ms.date: 2/6/2024
55
ms.service: "visual-cpp"
66
ms.subservice: "cpp-lang"
77
---
88
# C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2022
99

10-
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.
10+
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.
1111

1212
This document lists the changes in Visual Studio 2022.
1313

14-
For a guide to the changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).\
14+
For changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).\
1515
For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md).\
16-
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).
16+
For changes in older versions, see [Visual C++ What's New 2003 through 2015](../porting/visual-cpp-what-s-new-2003-through-2015.md).
17+
18+
## <a name="improvements_179"></a> Conformance improvements in Visual Studio 2022 version 17.9
19+
20+
Visual Studio 2022 version 17.9 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
21+
22+
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).
23+
24+
### `__VA_OPT__` is enabled as an extension under `/Zc:preprocessor`
25+
26+
`__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.
27+
28+
For example, this now compiles without error:
29+
30+
```cpp
31+
#define LOG_WRAPPER(message, ...) WRITE_LOG(__LINE__, message __VA_OPT__(, __VA_ARGS__))
32+
33+
// Failed to build under /std:c11, now succeeds.
34+
LOG_WRAPPER("Log message");
35+
LOG_WRAPPER("Log message with %s", "argument")
36+
```
37+
38+
### C23 language ###
39+
40+
For C23, the following are available when using the `/std:clatest` compiler switch:
41+
42+
[`typeof`](../c-language/typeof-c.md)\
43+
[`typeof_unqual`](../c-language/typeof-unqual-c.md)
44+
45+
The following are available for all C language versions:
46+
47+
[`__typeof__`](../c-language/typeof-c.md)\
48+
[`__typeof_unqual__`](../c-language/typeof-unqual-c.md)
49+
50+
### C++ Standard Library
51+
52+
**C++23 features**
53+
54+
- `formattable`, `range_format`, `format_kind`, and `set_debug_format()` as part of [P2286R8 Formatting Ranges](https://wg21.link/P2286R8)
55+
- `<mdspan>` per [P0009R18](https://wg21.link/P0009R18) and subsequent wording changes that were applied to the C++23 Standard.
56+
- `format()` pointers per [P2510R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2510r3.pdf).
1757
1858
## <a name="improvements_178"></a> Conformance improvements in Visual Studio 2022 version 17.8
1959
@@ -315,7 +355,7 @@ bidi.cpp(8): warning C5255: unterminated bidirectional character encountered: 'U
315355

316356
### `from_chars()` `float` tiebreaker
317357

318-
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).
358+
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).
319359

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

@@ -483,7 +523,7 @@ int main(void)
483523
484524
### Error on a nondependent `static_assert`
485525
486-
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.
526+
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.
487527
488528
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.
489529
210 KB
Loading
40.5 KB
Loading
111 KB
Loading

0 commit comments

Comments
 (0)