Skip to content

fix: add missing "optional" include#5554

Merged
PastaPastaPasta merged 1 commit into
dashpay:developfrom
thephez:add-optional-include
Aug 30, 2023
Merged

fix: add missing "optional" include#5554
PastaPastaPasta merged 1 commit into
dashpay:developfrom
thephez:add-optional-include

Conversation

@thephez

@thephez thephez commented Aug 30, 2023

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

develop wouldn't compile due to this error:

In file included from test/ratecheck_tests.cpp:3:
./governance/governance.h:200:10: error: ‘optional’ in namespace ‘std’ does not name a template type
  200 |     std::optional<uint256> votedFundingYesTriggerHash;
      |          ^~~~~~~~
./governance/governance.h:11:1: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?
   10 | #include <governance/classes.h>
  +++ |+#include <optional>
   11 | #include <governance/object.h>
./governance/governance.h:242:10: error: ‘optional’ in namespace ‘std’ does not name a template type
  242 |     std::optional<CSuperblock> CreateSuperblockCandidate(int nHeight) const;
      |          ^~~~~~~~
./governance/governance.h:242:5: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?
  242 |     std::optional<CSuperblock> CreateSuperblockCandidate(int nHeight) const;
      |     ^~~
make[2]: *** [Makefile:17017: test/test_dash-ratecheck_tests.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory 'code/dash/src'
make[1]: *** [Makefile:17812: all-recursive] Error 1
make[1]: Leaving directory 'code/dash/src'
make: *** [Makefile:799: all-recursive] Error 1

What was done?

Added the missing include

How Has This Been Tested?

Compiled locally

Breaking Changes

N/A

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

utACK for squash merge; merging as this is pretty trivial

@PastaPastaPasta
PastaPastaPasta merged commit efa8974 into dashpay:develop Aug 30, 2023
@PastaPastaPasta PastaPastaPasta added this to the 20 milestone Aug 30, 2023
@thephez
thephez deleted the add-optional-include branch August 30, 2023 17:40
squidicuzz pushed a commit to stakecube/StakeCubeCoin that referenced this pull request Aug 31, 2023
PastaPastaPasta pushed a commit that referenced this pull request Sep 7, 2023
## Issue being fixed or feature implemented
Some headers or modules are used objects from STL without including it
directly, it cause compilation failures on some platforms for some
specific compilers such as #5554

## What was done?
Added missing includes and removed obsolete includes for `optional`,
`deque`, `tuple`, `unordered_set`, `unordered_map`, `set` and `atomic`.

Please, note, that this PR doesn't cover all cases, only cases when it
is obviously missing or obviously obsolete.

Also most of changes belongs to to dash specific code; but for cases of
original bitcoin code I keep it untouched, such as missing <map> in
`src/psbt.h`

I used this script to get a list of files/headers which looks suspicious
`./headers-scanner.sh std::optional optional`:
```bash
#!/bin/bash

set -e

function check_includes() {
    obj=$1
    header=$2
    file=$3

    used=0
    included=0

    grep "$obj" "$file" >/dev/null 2>/dev/null && used=1
    grep "include <$header>" $file >/dev/null 2>/dev/null && included=1
    if [ $used == 1 ] && [ $included == 0 ]
        then echo "missing <$header> in $file"
    fi
    if [ $used == 0 ] && [ $included == 1 ]
        then echo "obsolete <$header> in $file"
    fi
}
export -f check_includes

obj=$1
header=$2

find src \( -name '*.h' -or -name '*.cpp' -or -name '*.hpp' \) -exec bash -c 'check_includes "$0" "$1" "$2"'  "$obj" "$header"  {} \;
```

## How Has This Been Tested?
Built code locally

## Breaking Changes
n/a


## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone
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.

2 participants