TomHarte / CLK

A latency-hating emulator of: the Acorn Electron and Archimedes, Amstrad CPC, Apple II/II+/IIe and early Macintosh, Atari 2600 and ST, ColecoVision, Enterprise 64/128, Commodore Vic-20 and Amiga, MSX 1/2, Oric 1/Atmos, early PC compatibles, Sega Master System, Sinclair ZX80/81 and ZX Spectrum.
MIT License
910 stars 50 forks source link

warning: control reaches end of non-void function [-Wreturn-type] #1360

Closed ryandesign closed 2 months ago

ryandesign commented 2 months ago

Building the latest code from the repo on Linux with cmake (which uses -Wall -Wextra) and g++ 11.4.0, I get these warnings:

.../CLK/Components/9918/Implementation/../Implementation/PersonalityTraits.hpp: In function ‘constexpr size_t TI::TMS::memory_size(TI::TMS::Personality)’:
.../CLK/Components/9918/Implementation/../Implementation/PersonalityTraits.hpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
.../CLK/Machines/Acorn/Archimedes/../../../InstructionSets/ARM/Registers.hpp: In static member function ‘static constexpr uint32_t InstructionSet::ARM::Registers::pc_offset_during(InstructionSet::ARM::Registers::Exception)’:
.../CLK/Machines/Acorn/Archimedes/../../../InstructionSets/ARM/Registers.hpp:188:17: warning: control reaches end of non-void function [-Wreturn-type]
  188 |                 }
      |                 ^

I think this is because although you've handled all the enumeration cases, you haven't handled the hypothetical case of a some other integer being passed to these functions. While that situation probably doesn't arise, the warning could be silenced by adding a default case. In other functions I've seen you use:

https://github.com/TomHarte/CLK/blob/018f0e097fabe264695561e4e18cb46297cc083b/InstructionSets/M50740/Parser.hpp#L68

ryandesign commented 2 months ago

Although now I learn that if you do add a default to a switch where you've handled all the enumeration cases, clang (if using -Weverything or just -Wcovered-switch-default) will say warning: default label in switch which covers all enumeration values. And there is a concern that if you add a default now and add more values to the enumeration later, you will not be warned that you haven't handled them separately in the switch. So perhaps just a return at the end of the function is the answer.