<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68339>68339</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang issues warning re undefined behavior on code that is never executed
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
fgrandel
</td>
</tr>
</table>
<pre>
**How to reproduce?**
Compile the following piece of C code:
```c
#include <stdio.h>
int ticks = 0 ? 1 / 0 : 0 ;
int main(int argc, char **argv)
{
printf("%d\n", ticks);
}
```
Triggers: "division by zero is undefined [-Wdivision-by-zero]"
See this example on [godbolt.org](https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1AB9U8lJL6yAngGVG6AMKpaAVxYMQAJlIOAMngMmABy7gBGmMQgABykAA6oCoS2DM5uHt7xickCAUGhLBFRsZaY1ilCBEzEBGnunj6l5QKV1QR5IeGRMRZVNXUZjX3tgZ2F3dEAlBaorsTI7BwApF4AzIHIblgA1EurjgoE%2BKgAdAh72EsaAIJX14EE2zbIANYKu6sAItsaHwBi2y42wA9D9tiAwXsAEJ3O4PbYsJiBCDw6rAczbZAIarbABUuLRADdJrCAOwwm7bKnUqlxYgPKgQFZeFYAVnQS1ZjgYzNITzwrwUJNWFNupM%2BHGmtE4rN4ng4WlIqE4jm2Clm80wuzWPFIBE0kumLxAkmiJwAbNFJF4uBpWV5zasuKzSQBOVn6TiSXgsCQaDSkeWK5UcXgKEAB/UKyWkOCwGCIFCoFhxOiRciUNAptNRZCbQzALikjRcUhYQkCzAANTwmAA7gB5OKMTi6mi0AiRcMQMIG0hhQLVACerd4A%2BYxCHDbC2jKUd1WbYggbDFoI%2BjZcwYVcwEcYlo4e4vCwiKM4g3%2BGIc7whMwh8VmFUZVcndH5EEmGlR/0eDCxGHzhYH2BD0r6R7TFQBjAAoNb1k2LbfvwggiGI7BSDIgiKCo6gbropYGEYICmMY5i0L%2B4aQNMqBxDYAiHgAtA2qy8Kgt7EPSWAURA0xNLRngQA4AyeKW/ijAURR6AkSR8UJknZHxHTid0pa8RUwyySpn7Xi0wyKV0UQqepLj1HohxtHp4wGTxGoLHodaGAQTYEAAkgw/CjlKMpyn2IbbKo0TmvR5qSJiBHAICpInBoJxAhAuCECQ2pOpMvBRlokxGiArJcCcToutErqSKSqyWtaPhft6pC%2Bqsqy5TV9UNQ15qBj5nBhhGeoGtMcaJngZAUBAWapvQxDBKwiz%2BYFwWhQWEVRTFvCYPgRAcXoSHCKI4joetWFqH2eEWFpzT8YJxkZCJDDoBZEmllJOSpGdwlZNJKTXcph1WHxrT9I9plHV9ulifpplGekT1mTUb1WXqV6YHg6ARp5HCyi1G4hn4fhVgAstszkAErbLBdaRH5AVBSF%2BZGHN0WxfFK1JaW2zONmI0MylnXRhlpAIJgTBYFE3GehwlXVbVjXi/VzVBixbUWB1aUxj1EBILMBBxC%2BGaDcmw2RGNbCcJN5MzVTXA5dFD7LSQ8NrbIKFbdIO1KHtuF2f%2BcQeULKPS0qnANi%2B6uPKgVCk1NFNhdTMXbBAzM68QbOpV1SMiyANV1RLjWo8GsvhpGiekMa2W5c6pIFUVJVWl45WcMxmcy6GHPpUjXjeWjssK1zbFJHYkhAA%3D%3D).
**Expected**
No warning as code that is not executed cannot be undefined behavior at least if one agrees with the following interpretation of the standard:
https://stackoverflow.com/questions/18385020/can-code-that-will-never-be-executed-invoke-undefined-behavior
This is essentially equivalent to the common `if (x == 0) x; else 1/x;` pattern.
The relevance becomes more obvious if one introduces a re-usable preprocessor pattern:
`#define div_if_not_zero(a, b) ((b) ? (a)/(b) : 0)`
**Environment**
Tested with clang 11.0.0 to 17.0.1 on x86_64 (https://github.com/llvm/llvm-project.git e19b7dc36bc047b9eb72078d034596be766da350)
</pre>
<img width="1px" height="1px" al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