mapbox / mapbox/cpp

Excellent docs on numeric casting in C++

Open
#38 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
110
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Without strict compiler warnings, it is possible to write quite a bit of C++ without it be obvious once needs to study the details of numeric casting. Implicit conversion will convert various integer types to other integer types and to floating point types, quietly and hopefully correctly.

Because we can't have correct code based on hope, we should instead enable warnings from the get go that warn about implicit conversion and specifically truncating or narrowing conversion and convertions that might overflow.

So, we want to enable warnings like `-Wconversion` per #37.

What this means is that you'll get loud warnings right away about converting types and will need to figure out how to avoid or suppress them correctly, to fix the potential existing bugs they hint at and avoid creating new bugs in the process.

Refs https://github.com/mapbox/node-cpp-skel/pull/78#discussion_r144410926 https://github.com/mapbox/carmen-cache/issues/94
refs https://github.com/mapbox/gzip-hpp/pull/19#issuecomment-336537155

/cc @mapsam @GretaCB @flippmoke

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 issue #37 and the referenced discussions and pull requests to understand the intended warning configuration. Then inspect the repository's build configuration and compile with the proposed conversion warnings. Done means the warnings are enabled and the resulting existing truncation, narrowing, overflow, or implicit-conversion warnings are addressed or explicitly suppressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.