Skip to content

Conversation

@knst
Copy link
Collaborator

@knst knst commented Sep 1, 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 in src/psbt.h

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

#!/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:

  • 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

@knst knst added this to the 20 milestone Sep 1, 2023
@UdjinM6
Copy link

UdjinM6 commented Sep 1, 2023

LGTM but let's merge conflicting backports (#5546) first

ogabrielides
ogabrielides previously approved these changes Sep 3, 2023
Copy link

@ogabrielides ogabrielides left a comment

Choose a reason for hiding this comment

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

ACK

@knst
Copy link
Collaborator Author

knst commented Sep 4, 2023

LGTM but let's merge conflicting backports (#5546) first

I updated commit a bit to avoid conflict with #5546, please, check @UdjinM6

@knst knst force-pushed the fix-headers branch from a5258b2 to 423c922

@UdjinM6
Copy link

UdjinM6 commented Sep 4, 2023

Hmmm... but it breaks sorting for includes, I wouldn't do that. Let's ping @PastaPastaPasta and ask him to review #5546 ASAP (and then this PR after a rebase) instead and hope for the best :D

@thephez
Copy link
Collaborator

thephez commented Sep 5, 2023

Just got this one when trying to build v20.0.0-beta.1 (bc6360f6a)

In file included from ./rpc/util.h:8,
                 from test/script_tests.cpp:9:
./node/coinstats.h:39:10: error: ‘optional’ in namespace ‘std’ does not name a template type
   39 |     std::optional<CAmount> total_amount{0};
      |          ^~~~~~~~
./node/coinstats.h:13:1: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?
   12 | #include <streams.h>
  +++ |+#include <optional>
   13 | #include <uint256.h>

@knst knst force-pushed the fix-headers branch 2 times, most recently from bb17b88 to 233fb57 Compare September 6, 2023 09:50
@knst
Copy link
Collaborator Author

knst commented Sep 6, 2023

Hmmm... but it breaks sorting for includes, I wouldn't do that. Let's ping @PastaPastaPasta and ask him to review #5546 ASAP (and then this PR after a rebase) instead and hope for the best :D

Pulled latest develop, reverted re-ordering headers (assumed to avoid conflict) and added to more in src/util/overflow.h and src/node/coinstats.h

Copy link
Collaborator

@thephez thephez left a comment

Choose a reason for hiding this comment

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

ACK - this is builds for me

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK

Copy link

@ogabrielides ogabrielides left a comment

Choose a reason for hiding this comment

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

ACK

@knst
Copy link
Collaborator Author

knst commented Sep 7, 2023

@PastaPastaPasta please review it soon, develop fails without this PR on my workstation:

  CXX      test/test_dash-streams_tests.o
In file included from ./rpc/util.h:8,
                 from test/script_tests.cpp:9:
./node/coinstats.h:39:10: error: ‘optional’ in namespace ‘std’ does not name a template type
   39 |     std::optional<CAmount> total_amount{0};
      |          ^~~~~~~~
./node/coinstats.h:13:1: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?
   12 | #include <streams.h>
  +++ |+#include <optional>
   13 | #include <uint256.h>

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

utACK for squash merge

@PastaPastaPasta PastaPastaPasta merged commit f8befc8 into dashpay:develop Sep 7, 2023
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.

5 participants