Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jan 25, 2024

When unreachable code isn't compiled, compile failures are not detected.

Fix this by leaving it unreachable, but compiling it.

Fixes #28999 (comment)

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 25, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@maflcko
Copy link
Member Author

maflcko commented Jan 25, 2024

Can be tested by adding a compile failure to the unreachable code. On master compilation passes, here it fails.

When unreachable code isn't compiled, compile failures are not detected.

Fix this by leaving it unreachable, but compiling it.

Fixes bitcoin#28999 (comment)

Can be reviewed with --ignore-all-space
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 fa3373d. This looks good, and should prevent code in the else blocks from accidentally breaking.

Maybe a way to make it a little clearer would be to define use_bdb and use_sqlite c++ constants like:

constexpr bool use_bdb{
#ifdef USE_BDB
true
#endif
};

Then the actual code could use if constexpr(use_bsb) like a normal conditional. This might be more verbose than the current approach, though, and the current approach does seem fine.

@maflcko
Copy link
Member Author

maflcko commented Jan 25, 2024

Then the actual code could use if constexpr(use_bsb) like a normal conditional.

This wouldn't work, because the #ifdef is still needed to "erase" the MakeSQLiteDatabase code. Recall that the header that declares MakeSQLiteDatabase isn't included when sqlite isn't selected by configure. (Same for bdb)

@ryanofsky
Copy link
Contributor

This wouldn't work, because the #ifdef is still needed to "erase" the MakeSQLiteDatabase code. Recall that the header that declares MakeSQLiteDatabase isn't included when sqlite isn't selected by configure. (Same for bdb)

Good point. There could be a number of ways to fix this (rearranging headers, using forward declarations), but probably not worth it

@achow101
Copy link
Member

ACK fa3373d

@achow101 achow101 merged commit 717103b into bitcoin:master Jan 25, 2024
@maflcko maflcko deleted the 2401-code-reach- branch January 26, 2024 08:04
@vasild
Copy link
Contributor

vasild commented Feb 16, 2024

When unreachable code isn't compiled, compile failures are not detected.

Another approach to this is to run CI with both USE_BDB defined and USE_BDB undefined.

Fix this by leaving it unreachable, but compiling it.

This produces compiler warnings about unreachable code. I guess that if we are to have deliberately unreachable code, then some pragma is needed to tell compilers not to warn about it in those particular places where it is intended.

@maflcko
Copy link
Member Author

maflcko commented Feb 16, 2024

Another approach to this is to run CI with both USE_BDB defined and USE_BDB undefined.

This is already done, but generally it is better to notify devs of compile failures immediately, instead of going through the lengthy CI pipeline.

This produces compiler warnings about unreachable code. I guess that if we are to have deliberately unreachable code, then some pragma is needed to tell compilers not to warn about it in those particular places where it is intended.

Yes, the reported issue is known and is already linked. if constexpr (true) is a standard way to achieve exactly that, without any pragmas. There is a single compiler out there that falsely prints a harmless warning. I don't understand why this has to be re-discussed in two threads over almost a month?

Anyone can revert the commit, if they think that reverting it solves a problem.

@bitcoin bitcoin locked and limited conversation to collaborators Feb 15, 2025
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.

5 participants