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/code-quality/c26498.md
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,4 +7,24 @@ helpviewer_keywords: ["C26498"]
7
7
---
8
8
# C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL
9
9
10
-
This function call %function% can use `constexpr` if compile-time evaluation is desired. See [C++ Core Guidelines con.5](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-constexpr).
10
+
This rule helps to enforce Con.5 from the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con5-use-constexpr-for-values-that-can-be-computed-at-compile-time): use constexpr for values that can be computed at compile time.
11
+
12
+
The warning is triggered by assigning the result of a constexpr function to any non-constexpr variable whose value doesn't change after the initial assignment.
13
+
14
+
# Example
15
+
```cpp
16
+
constexprintgetMyValue()
17
+
{
18
+
return 1;
19
+
}
20
+
21
+
voidfoo()
22
+
{
23
+
constexpr int val0 = getMyValue(); // no C26498
24
+
const int val1 = getMyValue(); // C26498, C26814
25
+
int val2 = getMyValue(); // C26498, value is never modified
26
+
int val3 = getMyValue(); // no C26498, val3 is assigned to below.
0 commit comments