openframeworks / openframeworks/openFrameworks

API safety: [[nodiscard]] for OF types constructors

Open
#7,585 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

I've been subject to expecting the drawing to be red without seeing the error on a line such as ofColor(255,0,0); . C++17 has [[nodiscard]] to raise warn users of such suspicious usage. applied to constructors (such as ofColor()) it means an unused object will produce a warning. so for instance applying [[nodiscard("did you mean to use ofSetColor()?")]] to ofColor() does this:

image

it's pretty evident once you notice it, but depending on the context (especially when moving around languages/toolkits) it might not be apparent because it's not an error per se. similar thing can happen with ofRectangle() vs ofDrawRectangle(). maybe others, too?

proposal: strengthen the OF API by adding [[nodiscard(...)]] to constructors of types likely to be confused with a function.

(requires the -Wunused-result flag ("unused values" in Xcode); turning it on does not produce spurious issues)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the API cases named in the issue, especially ofColor() versus ofSetColor() and ofRectangle() versus ofDrawRectangle(), then check how C++17 [[nodiscard]] and -Wunused-result behave in the supported builds. Done means agreeing on the constructors likely to be confused with drawing functions and documenting or applying the proposal consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.