Skip to content

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Feb 14, 2020

I overlooked a missing return false in #17577 (comment) and the warning only showed up on one Travis machine (warning: control reaches end of non-void function [-Wreturn-type]).

This PR promotes Wreturn-type to an error when configured with --enable-werror. I also added --enable-werror to the Travis machine that happened to catch this particular instance.

@Sjors Sjors changed the title build: add Wreturn-type to Werror flags, check on more Travis machines WIP build: add Wreturn-type to Werror flags, check on more Travis machines Feb 14, 2020
@Sjors
Copy link
Member Author

Sjors commented Feb 14, 2020

(don't merge this yet, I need to drop the last commit 4294b2f which should produce the error)

Proof that Travis indeed catches this: https://travis-ci.org/bitcoin/bitcoin/jobs/650359000#L2713

@Sjors Sjors force-pushed the 2020/return-type branch 2 times, most recently from 4294b2f to c98c26e Compare February 14, 2020 09:58
@Sjors Sjors changed the title WIP build: add Wreturn-type to Werror flags, check on more Travis machines build: add Wreturn-type to Werror flags, check on more Travis machines Feb 14, 2020
@vasild
Copy link
Contributor

vasild commented Feb 14, 2020

-Wreturn-type is enabled by default (even without -Wall) in clang and gcc:

https://releases.llvm.org/9.0.0/tools/clang/docs/DiagnosticsReference.html#wreturn-type
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

The following code:

enum Color {
    RED,
    BLUE
};

bool isWarm(Color c) {
    switch (c) {
    case RED:
        return true;
    case BLUE:
        return false;
    }
}

bool isCold(Color c) {
    if (c == BLUE) {
        return true;
    }
}

produces:

Clang 7.0.1, 8.0.1, 9.0.1 with no options, with just -Wall, with -Wall -Wreturn-type: only a warning for isCold(): warning: control may reach end of non-void function [-Wreturn-type].

GCC 9.2.0 with no options, with just -Wall, with -Wall -Wreturn-type: a warning for both functions: warning: control reaches end of non-void function [-Wreturn-type].

Clang is staying silent about isWarm() because it sees that all enumeration values are handled in the switch. If I remove the case BLUE:, then I get two warnings for isWarm():

warning: enumeration value 'BLUE' not handled in switch [-Wswitch]
warning: control may reach end of non-void function [-Wreturn-type]

That said, adding explicitly -Wreturn-type is unnecessary because it is enabled by default.

@vasild
Copy link
Contributor

vasild commented Feb 14, 2020

Ah! But we are using -Werror=whatever which selectively turns only some warnings into errors. Sorry for the noise above.

ACK c98c26e.

@practicalswift
Copy link
Contributor

practicalswift commented Feb 14, 2020

Thanks for working on this! I think we're currently somewhat underutilising the help we can get from compilers in the form of compiler diagnostics to prevent mistakes and this PR brings us in the right direction :)

ACK c98c26e

If you have time please consider submitting a PR enabling the subset of compiler diagnostics discussed in #17344 that you think make sense. I would be glad to review such PRs, so don't hesitate to ping me in for review.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 14, 2020

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.

maflcko pushed a commit that referenced this pull request Feb 16, 2020
…Travis machines

c98c26e ci: use --enable-werror on more hosts (Sjors Provoost)
6ba617d build: add Wreturn-type to Werror flags (Sjors Provoost)

Pull request description:

  I overlooked a missing `return false` in #17577 (comment) and the warning only showed up on one Travis machine (`warning: control reaches end of non-void function [-Wreturn-type]`).

  This PR promotes `Wreturn-type` to an error when configured with `--enable-werror`. I also added `--enable-werror` to the Travis machine that happened to catch this particular instance.

ACKs for top commit:
  vasild:
    ACK c98c26e.
  practicalswift:
    ACK c98c26e

Tree-SHA512: 64e86c67fef2c5048aab201a8400b7e4a6f27b93d626159ba0b2807b5f119d2b0a83e3372db88f692cb4b0d059722d6a642d130c74a4f991a27f3a6b21780b5f
@maflcko maflcko merged commit c98c26e into bitcoin:master Feb 16, 2020
@Sjors Sjors deleted the 2020/return-type branch February 16, 2020 17:25
kwvg added a commit to kwvg/dash that referenced this pull request Jun 17, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jun 17, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jun 17, 2021
UdjinM6 added a commit to dashpay/dash that referenced this pull request Jun 23, 2021
@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.

6 participants