Skip to content

Util: Add [[nodiscard]] to createView/createLocalView#5119

Merged
matejk merged 1 commit intomainfrom
4844-nodiscard-createview
Dec 18, 2025
Merged

Util: Add [[nodiscard]] to createView/createLocalView#5119
matejk merged 1 commit intomainfrom
4844-nodiscard-createview

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Dec 17, 2025

Summary

Adds [[nodiscard]] attribute and documentation to createView() and createLocalView() methods to help prevent use-after-free bugs.

Problem

Since POCO 1.11, these methods return AbstractConfiguration::Ptr (AutoPtr) instead of raw pointers. Code that assigns the return value to a raw pointer compiles but causes use-after-free:

// WRONG - compiles but crashes!
AbstractConfiguration* view = cfg->createView("prefix");
view->keys(keys);  // use-after-free

// CORRECT
AbstractConfiguration::Ptr view = cfg->createView("prefix");
// or: auto view = cfg->createView("prefix");

Changes

  • Added [[nodiscard]] attribute to warn when return value is discarded
  • Added documentation noting that the return value must be assigned to Ptr, not raw pointer

Related: Migration note added to CHANGELOG.md on branch 4383-rename-changelog.

@matejk matejk added this to the Release 1.15.0 milestone Dec 17, 2025
@matejk matejk merged commit 1e183e1 into main Dec 18, 2025
75 of 86 checks passed
@matejk matejk deleted the 4844-nodiscard-createview branch December 18, 2025 09:53
@matejk matejk changed the title fix(Util): Add [[nodiscard]] to createView/createLocalView (#4844) Util: Add [[nodiscard]] to createView/createLocalView Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant