Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Apr 13, 2020

Makes nonsensical stuff like ScriptToAsmStr(false,false); a compile failure

@laanwj
Copy link
Member

laanwj commented Apr 13, 2020

ACK 88884ee

@promag
Copy link
Contributor

promag commented Apr 13, 2020

ACK 88884ee.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@practicalswift
Copy link
Contributor

practicalswift commented Apr 13, 2020

ACK 88884ee

explicit is better than implicit.

More generally I think we should err on the safe side and only allow implicit conversions via explicit opt-in (instead of disallowing via explicit opt-out) :)

Copy link
Contributor

@jb55 jb55 left a comment

Choose a reason for hiding this comment

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

ACK 88884ee

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 88884ee

I think it's not possible for just marking a constructor explicit to change which overload a compiler chooses like sipa was speculating about in https://github.com/bitcoin/bitcoin/pull/18612/files#r407269834 (assuming no sfinae overloads). But might be worth verifying this PR doesn't change compiler output.

@maflcko
Copy link
Member Author

maflcko commented Apr 13, 2020

But might be worth verifying this PR doesn't change compiler output.

I get the same bin with gcc/clang on O2

@sipa
Copy link
Member

sipa commented Apr 13, 2020

@ryanofsky FWIW, that is not true in general.

The following code

#include <stdio.h>

struct A { };
struct B : public A { };
struct C {
    C(const A&) {printf("A\n");}
    C(const B&) {printf("B\n");}
};

int main(void) {
    const B objb = B();
    const C objc = objb;

    return 0;
}

will print B. When the C::C(const B&) constructor is marked explicit, it prints A. So it seems that:

  • Explicit constructors only match in explicit contexts.
  • deleted functions/constructors match just as much as non-deleted ones.
  • Among all matching functions the most specific one is chosen.
  • If the most specific one is deleted, there is an error.

@instagibbs
Copy link
Member

utACK 88884ee

@ryanofsky
Copy link
Contributor

@ryanofsky FWIW, that is not true in general.

Thanks, makes sense! I was thinking implicit constructor conversions would be pretty low in precedence but it makes sense derived-to-base conversions are lower

@fanquake fanquake merged commit 903be99 into bitcoin:master Apr 15, 2020
@maflcko maflcko deleted the 2004-scriptNoBool branch April 15, 2020 11:58
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 15, 2020
88884ee script: Disallow silent bool -> CScript conversion (MarcoFalke)

Pull request description:

  Makes nonsensical stuff like `ScriptToAsmStr(false,false);` a compile failure

ACKs for top commit:
  practicalswift:
    ACK 88884ee
  laanwj:
    ACK 88884ee
  promag:
    ACK 88884ee.
  instagibbs:
    utACK 88884ee
  jb55:
    ACK 88884ee
  ryanofsky:
    Code review ACK 88884ee

Tree-SHA512: 419d79c03b44a979c061b0540662928251ad68d53e65996bf370bb55ed1526ac7a22710cb7536c9954db5fec07bc312884bf8828f97a4ba180a5b07969a17f54
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 18, 2021
Summary:
> Makes nonsensical stuff like ScriptToAsmStr(false,false); a compile failure

This is a backport of Core [[bitcoin/bitcoin#18621 | PR18621]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8935
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
88884ee script: Disallow silent bool -> CScript conversion (MarcoFalke)

Pull request description:

  Makes nonsensical stuff like `ScriptToAsmStr(false,false);` a compile failure

ACKs for top commit:
  practicalswift:
    ACK 88884ee
  laanwj:
    ACK 88884ee
  promag:
    ACK 88884ee.
  instagibbs:
    utACK 88884ee
  jb55:
    ACK 88884ee
  ryanofsky:
    Code review ACK 88884ee

Tree-SHA512: 419d79c03b44a979c061b0540662928251ad68d53e65996bf370bb55ed1526ac7a22710cb7536c9954db5fec07bc312884bf8828f97a4ba180a5b07969a17f54
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 14, 2021
88884ee script: Disallow silent bool -> CScript conversion (MarcoFalke)

Pull request description:

  Makes nonsensical stuff like `ScriptToAsmStr(false,false);` a compile failure

ACKs for top commit:
  practicalswift:
    ACK 88884ee
  laanwj:
    ACK 88884ee
  promag:
    ACK 88884ee.
  instagibbs:
    utACK 88884ee
  jb55:
    ACK 88884ee
  ryanofsky:
    Code review ACK 88884ee

Tree-SHA512: 419d79c03b44a979c061b0540662928251ad68d53e65996bf370bb55ed1526ac7a22710cb7536c9954db5fec07bc312884bf8828f97a4ba180a5b07969a17f54
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants