Skip to content

Commit 005e650

Browse files
authored
Merge pull request #4989 from MicrosoftDocs/main
7/24/2023 10:30 AM Publish
2 parents 70982dc + 54ff8b5 commit 005e650

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

docs/error-messages/compiler-warnings/c4834.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ helpviewer_keywords: ["C4834"]
1313

1414
Starting in the C++17 Standard, the `[[nodiscard]]` attribute specifies that a function's return value isn't intended to be discarded. If a caller discards the return value, the compiler generates warning C4834.
1515

16-
To resolve this warning, consider why your code doesn't use the return value. Your use of the function may not match its intent. You can circumvent the warning by assigning the value to **`std::ignore`** or by using a cast to **`void`** (see [Warning C26457](../../code-quality/c26457.md)).
16+
To resolve this warning, consider why your code doesn't use the return value. Your use of the function may not match its intent. You can circumvent the warning by assigning the value to **`std::ignore`** or by casting it to **`void`** if discarding the value is intentional.
17+
Assignment to **`std::ignore`** is preferred over casting to **`void`** in C++ 11 and higher, as it makes your intent clearer and will not trigger [Warning C26457](../../code-quality/c26457.md) if enabled in your code analysis settings.
1718

1819
This warning was introduced in Visual Studio 2017 version 15.3 as a level 3 warning. It was changed to a level 1 warning in Visual Studio 2017 version 15.7. Code that compiled without warnings in versions of the compiler before Visual Studio 2017 version 15.3 can now generate C4834. For information on how to disable warnings introduced in a particular compiler version or later, see [Compiler warnings by compiler version](compiler-warnings-by-compiler-version.md).
1920

@@ -29,7 +30,7 @@ To turn off the warning for an entire project in the Visual Studio IDE:
2930

3031
## Example
3132

32-
This sample generates C4834, and shows three ways to fix it:
33+
This sample generates C4834, and shows four ways to fix it:
3334

3435
```cpp
3536
// C4834.cpp
@@ -39,15 +40,23 @@ This sample generates C4834, and shows three ways to fix it:
3940
[[nodiscard]]
4041
int square_of(int i) { return i * i; }
4142

43+
4244
int main()
4345
{
4446
square_of(42); // warning C4834: discarding return value of function with 'nodiscard' attribute
45-
// If ignoring the [[nodiscard] attribute is unintentional, to fix the warning, make use of the return value, as shown here:
46-
// std::cout << "square_of(42) = " << square_of(42) << "\n";
47-
// If discarding the nodiscard value is intentional, but you cannot fix it another way (for example, if the function marked [[nodiscard]] is from a third-party dependency), you can also suppress the warning by assigning to std::ignore, as shown here:
48-
// std::ignore = square_of(42); // Ok, C++ 11 and higher
49-
// You can also suppress the warning by casting the return result to (void), but the intent of the cast may not be clear. This may produce warning C26457 depending on your code analysis settings.
50-
// (void) square_of(42); // warning C26457 if enabled
47+
// If ignoring the [[nodiscard] attribute is unintentional, make use of the return value as intended:
48+
// For example:
49+
std::cout << "square_of(42) = " << square_of(42) << "\n"; // Ok
50+
// Or:
51+
int result = square_of(43); // Ok
52+
std::cout << "square_of(43) = " << result << "\n";
53+
54+
// If ignoring the [[nodiscard]] attribute value is intentional, you have two options:
55+
// Preferrably, assign the return value to std::ignore:
56+
std::ignore = square_of(42); // Ok, C++ 11 and higher
57+
// Alternatively, you can cast the return value to void.
58+
// The intent may be less clear to other developers.
59+
(void) square_of(42); // May produce warning C26457
5160
return 0;
5261
}
5362
```

docs/intrinsics/umulh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ int main()
6262
unsigned __int64 result;
6363
result = __umulh(i, j); // result has the high 64 bits
6464
// of the product.
65-
printf_s("0x%I64x * 0x%I64x = 0x%I64x%I64x \n", i, j, result, k);
65+
printf_s("0x%016I64x * 0x%016I64x = 0x%016I64x_%016I64x \n", i, j, result, k);
6666
return 0;
6767
}
6868
```
6969

7070
```Output
71-
0x10 * 0xfedcba9876543210 = 0xfedcba98765432100
71+
0x0000000000000010 * 0xfedcba9876543210 = 0x000000000000000f_edcba98765432100
7272
```
7373

7474
**END Microsoft Specific**

0 commit comments

Comments
 (0)