mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
C++: Support std::addressof
I didn't add this support in `AddressConstantExpression.qll` since I think it would require extra work and testing to get the constexprness right. My long-term plan for `AddressConstantExpression.qll` is to move its functionality to the extractor.
This commit is contained in:
@@ -63,3 +63,18 @@ void nonexamples(int *ptr, int &ref) {
|
||||
nonexamples(&*ptr, ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace std {
|
||||
template<typename T>
|
||||
constexpr T *addressof(T &obj) noexcept {
|
||||
return __builtin_addressof(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void use_std_addressof() {
|
||||
int x = 0;
|
||||
int *y = std::addressof(x) + *std::addressof(x);
|
||||
}
|
||||
|
||||
// semmle-extractor-options: --clang
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
| addressOf.cpp:62:11:62:13 | ptr | |
|
||||
| addressOf.cpp:63:19:63:21 | ptr | |
|
||||
| addressOf.cpp:63:24:63:26 | ref | non-const address |
|
||||
| addressOf.cpp:71:32:71:34 | obj | |
|
||||
| addressOf.cpp:71:32:71:34 | obj | |
|
||||
| addressOf.cpp:77:27:77:27 | x | non-const address |
|
||||
| addressOf.cpp:77:48:77:48 | x | |
|
||||
| file://:0:0:0:0 | captured | |
|
||||
| file://:0:0:0:0 | captured | |
|
||||
| file://:0:0:0:0 | captured | non-const address |
|
||||
|
||||
Reference in New Issue
Block a user