Skip to content

Commit 06a4f90

Browse files
authored
Merge pull request #17109 from MathiasVP/constexpr-if-unevaluated
C++: Mark `constexpr if` as unevaluated
2 parents 6280ed2 + 61eda0d commit 06a4f90

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The controlling expression of a `constexpr if` is now always recognized as an unevaluated expression.

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ class Expr extends StmtParent, @expr {
307307
)
308308
or
309309
exists(Decltype d | d.getExpr() = this.getParentWithConversions*())
310+
or
311+
exists(ConstexprIfStmt constIf |
312+
constIf.getControllingExpr() = this.getParentWithConversions*()
313+
)
310314
}
311315

312316
/**

cpp/ql/test/library-tests/exprs/unevaluated/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ Virtual getAVirtual();
6262
void test9() {
6363
typeid(getAVirtual()); // unevaluated
6464
}
65+
66+
void constExprIf() {
67+
if constexpr(sizeof(int) == 4) { } // unevaluated
68+
}
69+
70+
// semmle-extractor-options: -std=c++20

cpp/ql/test/library-tests/exprs/unevaluated/unevaluated.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
| test.cpp:57:9:57:9 | 4 |
1515
| test.cpp:63:9:63:19 | call to getAVirtual |
1616
| test.cpp:63:9:63:21 | temporary object |
17+
| test.cpp:67:16:67:26 | sizeof(int) |
18+
| test.cpp:67:16:67:31 | ... == ... |
19+
| test.cpp:67:31:67:31 | 4 |
20+
| test.cpp:67:31:67:31 | (unsigned long)... |

0 commit comments

Comments
 (0)