https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100956
Bug ID: 100956 Summary: Unused variable warnings ignore "if constexpr" blocks where variables are conditionally used Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mattreecebentley at gmail dot com Target Milestone: --- For example, as part of a container class: void remove_memory_blocks(pointer back_element_in_final_block) { if constexpr(!std::is_trivially_destructible<element_type>::value) { // destroy each element in each memory block until the back_element is reached } // remove memory blocks } If element_type is_trivially_destructible, G++ will warn that back_element_in_final_block is unused every time the function is called. Ideally this warning should be performed before constexpr blocks are removed by a parser (I have no idea what the procedure is for GCC, I'm just guessing here)