Skip to content

Replace Global Namespace Type Aliases with STD:: Prefixed Equivalents#5105

Draft
bska wants to merge 1 commit intoOPM:masterfrom
bska:replace-bare-types-with-std-names
Draft

Replace Global Namespace Type Aliases with STD:: Prefixed Equivalents#5105
bska wants to merge 1 commit intoOPM:masterfrom
bska:replace-bare-types-with-std-names

Conversation

@bska
Copy link
Copy Markdown
Member

@bska bska commented Apr 10, 2026

Modernize the codebase by replacing all bare C type aliases (size_t, int64_t, uint64_t, etc.) with their std::-qualified counterparts, making namespace usage explicit and consistent throughout.

Changes

  • Type replacements across 219 files in opm/ and tests/:

    • size_tstd::size_t (~1600 occurrences)
    • int64_tstd::int64_t (~134 occurrences)
    • uint64_tstd::uint64_t (~32 occurrences)
    • uint32_tstd::uint32_t, intptr_tstd::intptr_t (handful each)
  • Headers added where missing, placed in alphabetical order:

    • #include <cstddef> for std::size_t / std::ptrdiff_t
    • #include <cstdint> for fixed-width integer types

Scope

  • Types in comments and string/raw-string literals are left unchanged
  • Vendored third-party code (external/resinsight/) is not touched
  • Already-qualified std::size_t etc. are not duplicated

Example

// Before
size_t computeIndex(int64_t id, uint64_t offset);

// After
std::size_t computeIndex(std::int64_t id, std::uint64_t offset);
Original prompt

Objective

Replace all uses of "bare" type aliases (those in the global namespace) with their std:: namespaced counterparts throughout the opm-common codebase. This modernizes the code and makes the namespace usage explicit and consistent.

Types to Replace

Replace the following bare types with their std:: equivalents:

Fixed-width integer types (require <cstdint>)

  • int8_tstd::int8_t
  • int16_tstd::int16_t
  • int32_tstd::int32_t
  • int64_tstd::int64_t
  • uint8_tstd::uint8_t
  • uint16_tstd::uint16_t
  • uint32_tstd::uint32_t
  • uint64_tstd::uint64_t
  • intptr_tstd::intptr_t
  • uintptr_tstd::uintptr_t
  • intmax_tstd::intmax_t
  • uintmax_tstd::uintmax_t

Size and pointer difference types (require <cstddef>)

  • size_tstd::size_t
  • ptrdiff_tstd::ptrdiff_t

Requirements

  1. Search comprehensively: Find all occurrences of these bare types in:

    • Function parameters
    • Return types
    • Variable declarations
    • Type aliases/typedefs
    • Template parameters
    • Cast expressions
  2. Preserve correct usage: Do NOT change:

    • Types already prefixed with std::
    • Types that are custom type names that happen to match these names
    • Types in comments (unless updating documentation to match code changes)
    • Types in string literals
  3. Add necessary headers: When replacing types, ensure the appropriate header is included:

    • Add #include <cstdint> when using std::int*_t or std::uint*_t types
    • Add #include <cstddef> when using std::size_t or std::ptrdiff_t
    • Place includes in alphabetical order with other system headers
    • Avoid duplicate includes
  4. Maintain code functionality: Ensure all replacements maintain exact functional equivalence with the original code.

  5. Handle edge cases properly:

    • Be careful with size_t in template contexts
    • Preserve any using declarations that might exist
    • Check for qualified usage (e.g., ::size_t should become std::size_t)

Example Transformations

Before:

#include <vector>

size_t computeSize(const std::vector<int>& data) {
    return data.size();
}

void process(uint64_t id, int32_t value) {
    // implementation
}

After:

#include <cstddef>
#include <cstdint>
#include <vector>

std::size_t computeSize(const std::vector<int>& data) {
    return data.size();
}

void process(std::uint64_t id, std::int32_t value) {
    // implementation
}

Scope

  • Focus on C++ source files (.cpp, .hpp, .h, .cc, .hxx, .cxx)
  • Make changes across the entire repository
  • Ensure consistency across all modified files

Testing Considerations

After making these changes, the code should:

  • Compile without errors
  • Maintain all existing functionality
  • Pass existing test suites

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Hi there,

The opm-common source base has been developed over a rather long time and some historical artifacts show up. In particular, there are numerous uses of "bare" size_t, int64_t and other type aliases for which we should use their "std" namespaced alternatives.

I'd like you to search the code base in bska/opm-common and replace all these "bare" types, i.e., in the global namespace, with their "std" counterparts. Please remember to also include the necessary headers when making such changes.

The end result of this work should be a pull request against the bska/opm-common repository fork.

Assistant: I'll create a pull request to replace bare type aliases with their std:: counterparts throughout the opm-common codebase.

Assistant: I'm waiting for your approval to proceed with creating a pull request that will replace all bare type aliases (like size_t, int64_t, etc.) with their std:: namespaced equivalents throughout the bska/opm-common repository.


This pull request was created from Copilot chat.

Agent-Logs-Url: https://github.com/bska/opm-common/sessions/d95e6a81-b15e-49f6-abc6-afccbffa3a07

@bska bska added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Apr 10, 2026
@bska
Copy link
Copy Markdown
Member Author

bska commented Apr 10, 2026

To Release Manager: This work is not intended for the upcoming 2026.04 release. I was just scratching an old itch and there's no rush to review/merge this. I will keep the PR updated as needed.

@bska
Copy link
Copy Markdown
Member Author

bska commented Apr 10, 2026

jenkins build this please

@SoilRos
Copy link
Copy Markdown
Member

SoilRos commented Apr 10, 2026

Note that std::int64_t, std::uint64_t, and std::uint32_t are optional and there might be a compiler out there that does not have it. For 99.9% of the situations, the std::int_least64_t, std::uint_least64_t, and std::uint_least32_t are the right replacements. std::intptr_t is also optional, but there is no clear alternative. If it's not stored, then std::uintmax_t would do the job. On the other hand, if it's stored (unlikely), I would store the pointer directly and convert to std::uintmax_t (or std::intptr_t when available) whenever is needed.

@bska
Copy link
Copy Markdown
Member Author

bska commented Apr 10, 2026

Note that std::int64_t, std::uint64_t, and std::uint32_t are optional and there might be a compiler out there that does not have it.

Doesn't matter. Those that have it will be the exact same ones that we're already using. This PR is exclusively about replacing size_t (and others) from the global namespace with the same type aliases from the standard namespace.

@bska bska force-pushed the replace-bare-types-with-std-names branch from 0514536 to 021b304 Compare April 10, 2026 15:25
@bska
Copy link
Copy Markdown
Member Author

bska commented Apr 10, 2026

jenkins build this please

@bska bska force-pushed the replace-bare-types-with-std-names branch 12 times, most recently from 738935f to 9a3f272 Compare April 17, 2026 15:20
@bska
Copy link
Copy Markdown
Member Author

bska commented Apr 20, 2026

jenkins build this please

@bska bska force-pushed the replace-bare-types-with-std-names branch 5 times, most recently from 767e1f6 to e0b1285 Compare April 29, 2026 12:10
@bska
Copy link
Copy Markdown
Member Author

bska commented Apr 29, 2026

jenkins build this please

@bska bska force-pushed the replace-bare-types-with-std-names branch 4 times, most recently from f21d595 to 5b6bd53 Compare May 5, 2026 10:12
@bska bska force-pushed the replace-bare-types-with-std-names branch 3 times, most recently from 1445622 to 7666007 Compare May 7, 2026 15:14
@bska bska force-pushed the replace-bare-types-with-std-names branch from 7666007 to 4eac84e Compare May 7, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants