Skip to content

Language level control in code is error prone #281

Open

Description

@martis42

This issue has multiple aspects. I will gather them here since they are semantically connected.

The problem

Brittle boost::wave::need_cppXX(..) usage

The need_cppXX() functions return true for exactly the chosen language version. Consequently, all places wanting a branch being active for version XX and following have to do need_cppXX() || need_cppYY() || need_cppZZ() || ... Besides being suboptimal code code readability, it is also easy to forget extending one of those constructs when adding a language version.

In my recent contributions I found such an existing bug by chance.

Managing the C++ language version in 2 ways with the programmatic API and the BOOST_WAVE_SUPPORT_CPPXX macros

Code readability and maintaining suffer in my opinion due to those constructs all over the plase:

#if BOOST_WAVE_SUPPORT_CPPXX != 0
	// Do something requiring at least version XX
#endif
#if BOOST_WAVE_SUPPORT_CPPYY != 0
 	// Do something requiring at least version YY
#endif

Proposal

Better express desired logic for "active starting from C++ version XX"

Introduce functions boost::wave::need_at_least_cppXX(..):

  • Those are always true given the user chooses a language version >= XX. Those would allow replacing all the or chaining cases with a single expressive function.
  • Maybe we can even remove the need_cppXX functions. I can't think of a proper use case for them. This is optional. If there are use cases I do not see right now, they can also stay.

include/boost/wave/language_support.hpp always supports all C++ versions independent of BOOST_WAVE_SUPPORT_CPPXX macros

The only reason for the BOOST_WAVE_SUPPORT_CPPXX I can think of is performance optimization. This does in my opinion not really matter for what happens in include/boost/wave/language_support.hpp.
Having the enum and selection/check functions for all C++ versions and features always available is the precondition for at some point writing code no longer using the BOOST_WAVE_SUPPORT_CPPXX macros pattern.

This part of the proposal can be rejected and we can still implement need_at_least_cppXX(..). But we should decide first, as both parts of the proposal touch include/boost/wave/language_support.hpp.

Activity

  1. jefftrull commented on Oct 30, 2026

    @jefftrull
    Collaborator

    I'll look at this soon but in the meantime please LMK if this means we have a bug in the soon-to-be-released Boost 1.93. Thanks.

  2. martis42 commented on Oct 31, 2026

    @martis42
    ContributorAuthor

    @jefftrull Sorry I formulated this poorly. The statement In my recent contributions I found such an existing bug by chance. referenced the already merged fix done as part of #276.
    Potentially the same issue exists somewhere else - it is an error one can easily make - but I a not aware of any concrete case.

    TL;DR: This is a proposal to increase code maintainability and make bugs less likely, not a report of a concretely identified bug being present right now.

  3. jefftrull commented on Nov 1, 2026

    @jefftrull
    Collaborator

    I would be happy to see a PR for DWYU applied to the Wave codebase :)

  4. martis42 commented on Nov 6, 2026

    @martis42
    ContributorAuthor

    I would be happy to see a PR for DWYU applied to the Wave codebase :)

    DWYU is quite focused on the Bazel build system. Unless you want to natively support a Bazel build with boost.wave I fear you can't profit from it 😅

  5. jefftrull commented on Nov 9, 2026

    @jefftrull
    Collaborator

    You don't want to use "bjam"? 😆

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions