Skip to content

Conversation

@mikomikotaishi
Copy link
Contributor

@mikomikotaishi mikomikotaishi commented Jan 8, 2026

Addresses part of #5152. This PR adds [[nodiscard]] attributes to many methods and types that would otherwise be important not to discard.

Unlike POCO_DEPRECATED() which can be disabled, I am not going to put [[nodiscard]] behind a macro as using deprecated symbols is intended while discarding a value is certainly a programming error.

@mikomikotaishi mikomikotaishi force-pushed the main branch 4 times, most recently from c5add77 to 6f042a9 Compare January 8, 2026 16:19
@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jan 8, 2026

I have also moved POCO_UNUSED to [[maybe_unused]], seeing as it is a standard attribute in C++17, but I think this is probably not needed any more. POCO_UNUSED has been removed entirely as [[maybe_unused]] is a standard attribute and is portably representable.

@mikomikotaishi mikomikotaishi force-pushed the main branch 2 times, most recently from 7dbfa1f to d77d238 Compare January 8, 2026 17:12
@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jan 9, 2026

Would it be possible to get this merged before the 1.15 release? I understand if not, but it is nearly done. I have covered all methods across the project.

@mikomikotaishi mikomikotaishi force-pushed the main branch 6 times, most recently from 479e634 to 6f154e8 Compare January 9, 2026 10:04
Copy link
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@matejk
Copy link
Contributor

matejk commented Jan 10, 2026

Would it be possible to get this merged before the 1.15 release? I understand if not, but it is nearly done. I have covered all methods across the project.

It is quite a big change. I'll need some time for review.

@mikomikotaishi mikomikotaishi changed the title Add [[nodiscard]] attributes enh(all): Add [[nodiscard]] and [[maybe_unused]] attributes Jan 10, 2026
@matejk
Copy link
Contributor

matejk commented Jan 12, 2026

There are lots of changes. Instead of adding comments to the source code I provide some general observations.

@matejk
Copy link
Contributor

matejk commented Jan 12, 2026

[[nodiscard]] on Enum Types

  enum [[nodiscard]] EventType { ... }
  enum [[nodiscard]] Priority { ... }
  enum [[nodiscard]] SelectMode { ... }
  enum [[nodiscard]] Storage { ... }
  enum [[nodiscard]] Allocation : unsigned char { ... }

This is unusual and mostly useless. [[nodiscard]] on an enum means functions returning that enum type should have their return value checked. But enum values are typically used as parameters, not return values. The attribute on the enum declaration itself doesn't do anything for enum values.

@matejk
Copy link
Contributor

matejk commented Jan 12, 2026

[[nodiscard]] on Internal/Helper Classes

  class [[nodiscard]] FunctorRunnable: public Runnable { ... }
  class [[nodiscard]] ValueHolder { ... }
  class [[nodiscard]] Block { ... }
  class [[nodiscard]] FDCompare { ... }

These are internal classes that users don't directly construct or receive from functions. Adding [[nodiscard]] adds noise without benefit.

@matejk
Copy link
Contributor

matejk commented Jan 12, 2026

[[nodiscard]] on Dereference Operators

  [[nodiscard]] C* operator -> ()
  [[nodiscard]] C& operator * ()

This is wrong. These operators are used for accessing members:

  ptr->doSomething();  // This would warn! The return of -> is "discarded"

The -> operator result IS used implicitly. This will likely cause spurious warnings.

@matejk
Copy link
Contributor

matejk commented Jan 12, 2026

[[nodiscard]] on Nullable and Optional Classes

  class [[nodiscard]] Nullable { ... }
  class [[nodiscard]] Optional { ... }

Reconsider this. While it ensures you use the object, these types are commonly constructed just to be assigned to variables or passed around. The standard library's std::optional is not marked nodiscard.

@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jan 12, 2026

I decided to put nodiscard on enums and class internal types because I wanted to ensure that data like this is not discarded.

I have gone ahead and applied your requested changes, nonetheless.

@matejk
Copy link
Contributor

matejk commented Jan 13, 2026

@mikomikotaishi , you don't have to force push. It is harder to track changes between the commits when force pushed.

@mikomikotaishi
Copy link
Contributor Author

Noted

@andrewauclair
Copy link
Contributor

While it ensures you use the object, these types are commonly constructed just to be assigned to variables or passed around.

Not sure what you mean by this, but [[nodiscard]] on the enum or class declaration only applies to functions returning that type by value.

@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jan 15, 2026

Is there anything else I should address in this PR, pending reviews from the other reviewers?

@matejk
Copy link
Contributor

matejk commented Jan 16, 2026

Build with enabled compiler warnings shall be inspected whether introduction of attributes introduced new warnings and then decide how to fix those warnings:

  • change the code at the warning point
  • revert introduction of the attribute

Two jobs with enabled warnings are built on github: macos-clang-cmake-warnings and macos-msvc-cmake-warnings.

@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jan 17, 2026

Apologies, accidentally force-pushed instead of creating a new commit. (I'll force-push when making amendments from now on and use proper commits when adding something new.)

Anyway, I think I've done what I can to remove the warnings we were getting.

@mikomikotaishi mikomikotaishi force-pushed the main branch 9 times, most recently from f558a6f to 993c2ff Compare January 17, 2026 16:19
@mikomikotaishi
Copy link
Contributor Author

Never mind, I see the problem now, I accidentally overwrote the handled variable.

@mikomikotaishi
Copy link
Contributor Author

@matejk Is there anything to do next?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants