-
Notifications
You must be signed in to change notification settings - Fork 37.8k
script: Remove undocumented and unused operator+ #18612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -487,15 +473,6 @@ class CScript : public CScriptBase | |||
return *this; | |||
} | |||
|
|||
CScript& operator<<(const CScript& b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting this is dangerous, as attempts to call it will still work, except they'll use the function above instead (CScript::operator<<(const std::vector<unsigned char>&)
).
I think it could be made into a static check too:
Better solution:
CScript& operator<<(const CScript& b) = delete;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldn't use the above. I tested and this is the error:
error: invalid operands to binary expression ('CScript' and 'CScript')
./script/script.h:431:14: note: candidate function not viable: no known conversion from 'CScript' to 'int64_t' (aka 'long') for 1st argument
CScript& operator<<(int64_t b) { return push_int64(b); }
^
./script/script.h:433:14: note: candidate function not viable: no known conversion from 'CScript' to 'opcodetype' for 1st argument
CScript& operator<<(opcodetype opcode)
^
./script/script.h:441:14: note: candidate function not viable: no known conversion from 'CScript' to 'const CScriptNum' for 1st argument
CScript& operator<<(const CScriptNum& b)
^
./script/script.h:447:14: note: candidate function not viable: no known conversion from 'CScript' to 'const std::vector<unsigned char>' for 1st argument
CScript& operator<<(const std::vector<unsigned char>& b)
^
1 error generated.
I think you wanted to say that the non-existent operator should be explicitly deleted just as it has been done for the constructor in e1a5569?
If yes, I have done that. The error is now
error: overload resolution selected deleted operator '<<'
./script/script.h:430:14: note: candidate function has been explicitly deleted
CScript& operator<<(const CScript& b) = delete;
^
./script/script.h:432:14: note: candidate function not viable: no known conversion from 'CScript' to 'int64_t' (aka 'long') for 1st argument
CScript& operator<<(int64_t b) { return push_int64(b); }
^
./script/script.h:434:14: note: candidate function not viable: no known conversion from 'CScript' to 'opcodetype' for 1st argument
CScript& operator<<(opcodetype opcode)
^
./script/script.h:442:14: note: candidate function not viable: no known conversion from 'CScript' to 'const CScriptNum' for 1st argument
CScript& operator<<(const CScriptNum& b)
^
./script/script.h:448:14: note: candidate function not viable: no known conversion from 'CScript' to 'const std::vector<unsigned char>' for 1st argument
CScript& operator<<(const std::vector<unsigned char>& b)
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcoFalke Oh, I forgot that CScript isn't a vector anymore (but a prevector), so indeed the function above isn't viable. If we'd have an operator that pushes a prevector however (which would be implicitly added by #13062 for example), then having an explicitly deleted version for CScript still prevents it from being called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked that with Span, the output looks like this:
overload resolution selected deleted operator '<<'
script << s;
~~~~~~ ^ ~
./script/script.h:435:14: note: candidate function has been explicitly deleted
CScript& operator<<(const CScript& b) = delete;
^
./script/script.h:452:14: note: candidate function
CScript& operator<<(const Span& b)
^
./script/script.h:437:14: note: candidate function not viable: no known conversion from 'const CScript' to 'int64_t' (aka 'long') for 1st argument
CScript& operator<<(int64_t b) { return push_int64(b); }
^
./script/script.h:439:14: note: candidate function not viable: no known conversion from 'const CScript' to 'opcodetype' for 1st argument
CScript& operator<<(opcodetype opcode)
^
./script/script.h:447:14: note: candidate function not viable: no known conversion from 'const CScript' to 'const CScriptNum' for 1st argument
CScript& operator<<(const CScriptNum& b)
^
./script/script.h:454:14: note: candidate function not viable: no known conversion from 'const CScript' to 'const std::vector<unsigned char>' for 1st argument
CScript& operator<<(const std::vector<unsigned char>& b)
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if you're arguing in favor or against what I'm saying, but to be clear: marking it explicitly deleted is the right approach IMO (not just because it prevents reintroducing the problem, but also to make it easy to see this PR doesn't change behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I posted this for myself to remind me that your comment (#18612 (comment)) is right
dddde1c
to
4444902
Compare
utACK 4444902 It seems like a no-brainer to remove the |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
Concept ACK Non-existing is better than unused/undocumented :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 4444902
4444902
to
ccccd51
Compare
Rebased |
ACK ccccd51 |
… CScript.__add__ faff9e4 test: Remove unused, undocumented and misleading CScript.__add__ (MarcoFalke) Pull request description: See the corresponding pull bitcoin#18612 ACKs for top commit: laanwj: ACK faff9e4 provided it passes Travis Tree-SHA512: 5d9c4d5b6453c70b24a6960d3b42834e9b31f6dbb99ac47a6abfd85f2739d5372563e7188c22aceabeee1c37eb218bf580848356f4a77268d65f178a9419b269
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
Rewrite code that used CScript's operator+ for building name operations, following bitcoin/bitcoin#18612.
Summary: This is a backport of Core [[bitcoin/bitcoin#18612 | PR18612]] Test Plan: ``` ninja all check-all ninja bitcoin-fuzzers ``` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D8973
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
…oin#18612: script: Remove undocumented and unused operator+
…oin#18612: script: Remove undocumented and unused operator+
…oin#18612: script: Remove undocumented and unused operator+
…oin#18612: script: Remove undocumented and unused operator+ ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
ccccd51 script: Remove undocumented and unused operator+ (MarcoFalke) Pull request description: This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data. Removing the operator is also going to protect against accidentally reintroducing bugs like this bitcoin@6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used). ACKs for top commit: laanwj: ACK ccccd51 Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
This was removed in "bitcoin#18612: script: Remove undocumented and unused operator+".
This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data.
Removing the operator is also going to protect against accidentally reintroducing bugs like this 6ff5f71#diff-8458adcedc17d046942185cb709ff5c3L1135 (last time it was used).