Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CppCXY/cpp_ls
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.3
Choose a base ref
...
head repository: CppCXY/cpp_ls
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.1.4
Choose a head ref
  • 7 commits
  • 30 files changed
  • 1 contributor

Commits on Oct 30, 2026

  1. checks: dangling-return — a reference, pointer or view of something…

    … that dies with the call
    
    The first lifetime rule, and the narrow one the feasibility note argued for: it reports only what it can **prove**, and
    stays silent on everything a parameter or a caller owns.
    
    ```
    int& f() { int x = 0; return x; }                        reported: a local
    std::string_view g() { std::string s; return s; }        reported: a view of a local
    const std::string& h() { return std::string("x"); }      reported: a temporary
    const char* k() { std::string s; return s.c_str(); }     reported: a pointer a local handed out
    int* m() { int x = 0; return &x; }                       reported: the address of a local
    ```
    
    Silent by construction: a parameter (`std::string_view f(const std::string& s) { return s; }` is the caller's rule, not
    the function's), a static or namespace-scope name, a string literal, `*this`'s member, and any pointer whose target would
    need points-to analysis (`int* f() { return p; }`). The origin of the returned expression is asked of the scope tree —
    local, parameter, member, global, static — rather than guessed from the spelling.
    
    Measured against the two compilers, on the five reported shapes and four safe ones (`-Wall -Wextra`):
    
    ```
                                clang 18                                   g++ 15
    reference to a local        reference to stack memory… returned        reference to local variable returned
    view of a local             address of stack memory… returned          no warning
    reference to a temporary    returning reference to local temporary     returning reference to temporary
    pointer into a local        address of stack memory… returned          no warning
    address of a local          address of stack memory… returned          address of local variable returned
    four safe shapes            no warning                                 no warning
    ```
    
    So the rule is at least as complete as clang's own `-Wreturn-stack-address` on these fixtures and strictly more
    complete than g++'s — and it agrees with both about the safe shapes. AddressSanitizer is not available in this MinGW
    (`cannot find -lasan`), so the runtime half is the compiler's diagnostic rather than an ASan report.
    
    Measured on the corpora: the C++ corpus (16 files, 666 declarations) and the C corpus (3 files) are both still at **0
    findings** — the two member functions that return a `T const&` member of `*this` are exactly the shape that stays
    quiet.
    
    Pinned by `tests/lifetime.rs`: 11 tests, five shapes reported (with the message a reader gets), nine safe shapes and a
    lambda's own `return` silent, and one finding per return. Docs: `dangling-return` is in both diagnostics tables, and the
    counts moved from 26 to 27 rules. `cargo test --workspace --all-features`, clippy `-D warnings` and `cargo fmt --check`
    are clean.
    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    4143ccc View commit details
    Browse the repository at this point in the history
  2. index: a namespace alias offers the names of its target

    `std::views::` answered **0** names on the corpus's `ranges.cpp`, which includes `<ranges>` — the alias is
    `namespace views = ranges::views;` in that header, and every adapter (`filter`, `transform`, `reverse`, `drop`,
    `take`) is declared in `std::ranges::views`. An alias declares no names of its own, so a query for the names written in
    `std::views` finds the empty scope and stops.
    
    Three pieces:
    
    * **the fact records the target.** `namespace views = ranges::views;` is a `NamespaceDecl` with no body and a
      `NameExpr` after the `=`, and the index now stores that spelling in the fact's `type_of` — the existing field, so
      the codec is unchanged and only `FORMAT_VERSION` moves (6 → 7, with the "why" beside it).
    * **the query follows it.** `names_in_a_scope` asks the alias's own fact when the scope has no names, and looks the
      target up where the alias sits (`std::ranges::views`) and then as written — the two orders the language itself uses.
    * **the buffer's own aliases** take the same route through the scope tree, for a file whose header is not rendered yet.
    
    Measured after: completion after `std::views::` offers **21** names — `all`, `common`, `counted`, `drop`, `drop_while`,
    `elements`, `empty`, `filter`, … — where it offered 0 before.
    
    Also pinned, and **already correct at HEAD**: the `template` keyword is drawn as a keyword in both positions of
    `template <template <typename, typename> class Container, typename T>`. Reported from an editor as missing, and the new
    test asserts the two tokens the encoder produces — so the editor in question was running an older server binary, which
    the screenshot's hover confirms in a second way (VS Code shows the TextMate scope and no semantic token type).
    
    Measured: both corpora unchanged — C++ 16 files / 666 declarations / 0 errors / 0 findings / 8 of 8 members / 4 of 4
    types, C 3 files / 5 of 5 / 4 of 4. `cargo test --workspace --all-features`, clippy `-D warnings` and `cargo fmt
    --check` are clean. Tests: `a_namespace_alias_offers_the_names_of_its_target` and its header variant, plus
    `the_template_keyword_is_a_keyword_in_both_positions`.
    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    863e151 View commit details
    Browse the repository at this point in the history
  3. checks: dangling-field — a view, reference or pointer member that o…

    …utlives what it names
    
    The second lifetime rule, and the other half of the origin analysis the first one wrote. A member of a borrowing type
    (``std::string_view``, ``std::span<T>``, ``const std::string&``, ``const char*``) is reported when its initialiser is one
    of the two things that certainly die before the object does:
    
    ```
    struct S { std::string_view v; S(std::string s) : v(s) {} };          a by-value parameter, destroyed at the closing brace
    struct S { std::string_view v = std::string("x"); };                  a temporary, destroyed at the end of the statement
    struct S { const std::string& v; S() : v(std::string("x")) {} };      a reference member of a temporary
    struct S { const char* p; S(std::string s) : p(s.c_str()) {} };       a pointer into the parameter's buffer
    ```
    
    Silent by construction: a **reference or rvalue-reference parameter** (the caller owns the lifetime — the contract
    ``[[clang::lifetimebound]]`` writes down, and the same silence `dangling-return` keeps), a member of `*this`, a static or
    global, a string literal, an owning member (there is nothing to see), and a pointer whose target is not certain
    (``S(int* q) : p(q) {}``).
    
    The origin analysis moved into ``check/borrowed.rs`` and is shared with `dangling-return`, which is why that rule's 11
    tests are part of this commit and all still pass. Sharing it found a real defect in the first version: **a parameter was
    classified as a global**, because "outside the body" was asked before "written before the body begins" — silent for
    `dangling-return` (both answers are quiet there), wrong for this rule (a by-value parameter and a namespace-scope name
    differ in exactly the way it needs).
    
    Measured against the two compilers, on the four reported shapes and three safe ones (``-Wall -Wextra``):
    
    ```
                                              g++ 15                                clang 18
    view of a by-value parameter              no warning                            no warning
    view of a temporary                       no warning                            object backing the pointer will be destroyed…
    pointer into a by-value parameter         no warning                            no warning
    reference member of a temporary           a temporary bound to 'S::v' only …    no warning
    three safe shapes                         no warning                            no warning
    ```
    
    So two of the four are already warned about by a released compiler (one by each), and the other two — the by-value
    parameter cases — are the shapes Clang's Lifetime Safety analysis names *dangling field* and no released compiler
    reports yet. All three safe shapes are quiet in both, which is the false-positive half of the same measurement.
    
    Measured on the corpus: 16 files, 666 declarations, still **0 findings**, **8/8 members**, **4/4 types**. Tests: six new
    (`tests/lifetime.rs`, 17 in total), including the safe shapes and the compiler-comparison fixtures; the C++-only list in
    `tests/checks.rs` now has nine names, and the diagnostics table in both docs has the new row. `cargo test --workspace
    --all-features`, clippy `-D warnings` and `cargo fmt --check` are clean.
    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    dffdd7a View commit details
    Browse the repository at this point in the history
  4. checks: use-after-free — a free written here, or in the function th…

    …at was called
    
    The third lifetime rule, and the inter-procedural one: a free that happens inside another function is recorded on that
    function's **fact** — `DeclFact::frees`, a bit per parameter — so a call site can report it without seeing a body.
    
    ```
    void release(T* p) { delete p; }                 fact: frees = 1 << 0
    void f() { T* p = new T(); release(p); p->x; }   reported: `p` is used after its memory was freed
    ```
    
    The bits are decided at index time by a **must**-analysis: an unconditional `delete p;`, `delete[] p;`, `free(p)`,
    `std::destroy_at(p)`, or a call to a function whose own fact frees that argument. A free under an `if`, in a loop, or
    behind another call is not recorded — a caller that reads the pointer afterwards is then only *sometimes* wrong, and
    this rule reports only what is certain. `CODEC_VERSION` 33 and `FORMAT_VERSION` 8 carry the new field.
    
    The call site is a must-analysis too, over one function body: `delete`/`free`/`destroy_at`/`u.reset()`/a callee's
    effects mark a variable freed; a read through it (`p->x`, `*p`, `p[i]`) after that is the finding; assigning a fresh
    value clears the state, and a free inside a branch or a loop does not escape it.
    
    Measured on a folding fixture that includes `<string>` and `<vector>`: the first version asked each **fact** about its
    own body and walked the whole rendering per declaration, so the server no longer answered a request within its 30-second
    budget. The pass that fills the bits now does **one** walk over the file's declarations and then scans only each body —
    the same fixture answers in 13.7 s including the spawn and the indexing of two standard headers.
    
    Tested: eight new tests in `tests/lifetime.rs` (25 in that file), including the same-file helper, a helper from a
    header (a real directory, because a memory file's `#include` is not rendered by this harness), `free`, `reset()`,
    `delete[]`, a parameter freed and then read, and eight shapes that must stay quiet — a read before the free, a free in
    one branch, a reassigned pointer, a **conditional** free in the callee, a callee that does not free, another variable.
    
    Measured: the C++ corpus (16 files, 666 declarations) and the C corpus (3 files) are both still at **0 findings**, 8/8
    members and 4/4 types. Docs: `use-after-free` is in both diagnostics tables, the C++-only count is unchanged at nine,
    and the totals moved to 29 rules. `cargo test --workspace --all-features`, clippy `-D warnings` and `cargo fmt --check`
    are clean.
    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    5d788b4 View commit details
    Browse the repository at this point in the history
  5. parser: _BitInt is read in every standard, as every compiler does

    `struct bits { unsigned _BitInt(3) three : 3; _BitInt(13) signed_wide : 13; _BitInt(5) plain; unsigned _BitInt(4) other
    : 2; };` came out with **no members**: the grammar gated `_BitInt` on C23 alone, so a project whose standard was not
    detected — no compile database, a header opened on its own — read `_BitInt(3) three : 3` as an initialiser and a macro
    call.
    
    No compiler agrees with that gate. Measured with gcc 15: the four members compile with `-std=c99`, `-std=c11`,
    `-std=c17` and `-std=gnu89` (exit 0, no diagnostic); clang 18 accepts the same struct in `-std=c++23`; only g++ rejects
    it in C++. The bit now covers every standard the reader knows, and the detector around it is unchanged — a parenthesised
    width followed by an identifier, so an ordinary variable named `_BitInt` is still a variable.
    
    Verified:
    
    * the struct now yields its four members (`three`, `signed_wide`, `plain`, `other`) under the **default** configuration
      and under `-std=c99`, `-std=c11`, `-std=c17`, `-std=c23`, `-std=c++17` and `-std=gnu2x` — the new test in
      `extensions_gnu.rs` replaces one whose comment claimed the default was "supposed to fail";
    * at session level, in a project with `-std=c17` in the database and again with **no database at all**, `bits` answers
      all four members where it answered none;
    * the C corpus went from **23 to 24** declarations — the struct's last member is a declaration now — with 0 findings,
      5/5 members and 4/4 types; the C++ corpus is unchanged (16 files, 666 declarations, 0 findings, 8/8, 4/4).
    
    `cargo test --workspace --all-features`, clippy `-D warnings` and `cargo fmt --check` are clean.
    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    db96abd View commit details
    Browse the repository at this point in the history
  6. unreal: a [unreal] switch, ue-naming and ue-generate-body, and …

    …a simulated engine project
    
    UE code is C++ that is not readable as ordinary C++: `UCLASS()`, `GENERATED_BODY()` and `UPROPERTY(…)` come from the
    engine's headers and expand to nothing, and its naming rules are conventions no other project follows. Both are now
    supported, behind a switch the project sets:
    
    ```toml
    [unreal]
    enable = true
    ```
    
    `ue-naming` (Hint): a `UCLASS` without a `U`/`A`, a `USTRUCT` without `F`, a `UENUM` without `E`, a boolean member
    without `b`. `A` is accepted alongside `U` because which one a class is depends on a base another file may declare.
    `ue-generate-body` (Error): a `UCLASS`/`USTRUCT` whose body writes no `GENERATED_BODY()` — the engine's build tool
    replaces that macro with the reflection data, so the class does not compile without it. Older spellings
    (`GENERATED_UCLASS_BODY`, …) are accepted.
    
    Both are C++-only and off unless the project says it is Unreal; a `class Widget` in an ordinary project is not reported.
    
    **The rules read two texts, and that was the design problem.** The rendering this layer analyses is made after the
    preprocessor, so with a real (or simulated) engine header the annotation is *gone*: measured on the UE-like project, once
    its `CoreMinimal.h` resolved, `UCLASS()` vanished from the tree and only the class remained — the first version of the
    rules keyed on the macro call in the tree and silently stopped firing. They now read the **written** text (walking back
    from the declaration to the macro call that ends there, and looking inside the body's own text for
    `GENERATED_BODY`), while names and member types still come from the tree and are mapped into the file with the same
    `in_the_file` crossing every finding uses.
    
    `C:\Users\zc\Desktop\UE-like` is a **simulated** engine project, since there is no engine on this machine: a
    `CoreMinimal.h` with the macros expanded to nothing and `int32`/`TArray`/`FString`/`FVector` spelled as a module uses
    them, a clean UE module, and the same code with one violation of each rule. Measured:
    
    ```text
    CoreMinimal.h   0 parse errors, 0 findings
    Clean.h/.cpp    0 parse errors, 0 findings
    Bad.h           0 parse errors, 5 findings — ue-naming on MyActor, isReady, MyData, State; ue-generate-body on MyActor
    ```
    
    Tests: four in `tests/ue_lint.rs` (bad/clean/off-by-configuration/names), plus the ignored probe `tests/ue.rs` that
    opens the simulated project. The C++-only list went from nine to eleven rules, the totals from 29 to 31, and both doc
    pages and `configuration.md` say so — including a `[unreal]` section and the note that the macros are the project's
    headers rather than the configuration.
    
    Measured unchanged: the C++ corpus (16 files, 666 declarations, 0 findings, 8/8, 4/4) and the C corpus (3 files, 24
    declarations, 0 findings, 5/5, 4/4). Clippy `-D warnings`, `cargo fmt --check` and `cargo test --workspace --all-features`
    are clean.
    
    Known limit, found while wiring the fixture: a **relative** `-I` in `[compile] args` is not rooted at the workspace, so
    the simulated header is named by an absolute path in `UE-like/.cppls.toml`. That is a defect of the include-path layer,
    not of UE support, and is the next thing to fix.
    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    23568c0 View commit details
    Browse the repository at this point in the history
  7. clean typos

    CppCXY committed Oct 30, 2026
    Configuration menu
    Copy the full SHA
    be661cb View commit details
    Browse the repository at this point in the history
Loading