github / github/codeql

Make it more ergonomic to get the initializer of a variable declaration in C++

Open
#7,275 4 comments 0 reactions 0 assignees View on GitHub
C++ question
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

I would expect that if I have a `DeclStmt` or a `DeclarationEntry`, I should be able to directly get the `Initializer`s corresponding to those entries, if they exist. I don't see a way to directly do that, and currently I have to resort to this:
```codeql
Initializer getDeclStmtInitializer(DeclStmt ds) {
result.getDeclaration().getADeclarationEntry() = ds.getADeclarationEntry()
}
```

Could we add some methods into the standard library classes (i.e. `DeclStmt::getAnInitializer`, `Declaration::getAnInitializer` `DeclarationEntry::getInitializer()`, etc.), to make it easier to get variable declaration initializers so we don't have to resort to these types of helper functions?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.