<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/131127>131127</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Multiple false positives and false negatives in -Whigher-precision-for-complex-division
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Maetveis
      </td>
    </tr>
</table>

<pre>
    The `-Whigher-precision-for-complex-division` emitted when `-fcomplex-arithmetic=promoted` option is used and the target does not support a higher precison type has multiple false positives and false negatives:
- Clang warns but shouldn't when the divisor is a real value, this is just elementwise division, which is already precise if performed in the lower precision type.
- Clang doesn't warn but should, if the divisor is a complex value but the divident is real.
- Clang doesn't warn but should, if the operation is going to be performed in a different type than the divident due to usual arithmetic conversions and the new type is the largest precision for the target. (e.g. `__complex__ float / __complex__ double`).
- Clang doesn't warn but should when using the `/=` (divide and assign) operator.

[Reproducer on Compiler Explorer](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:1,endLineNumber:20,positionColumn:1,positionLineNumber:20,selectionStartColumn:1,selectionStartLineNumber:20,startColumn:1,startLineNumber:20),source:'double+__complex__+div_complex_real(double+__complex__+a,+double+b)+%7B%0A++++return+a+/+b%3B+//+This+should+not+warn+but+it+does!!%0A%7D%0A%0Adouble+__complex__+div_real_complex(double+a,+double+__complex__+b)+%7B%0A++++return+a+/+b%3B+//+This+should+warn+but+it+doesn!'t.%0A%7D%0A%0Adouble+__complex__+div_assign(double+__complex__+a,+double+__complex__+b)+%7B%0A++++return+a+/%3D+b%3B+//+This+should+warn+but+it+doesn!'t.%0A%7D%0A%0Adouble+__complex__+div_mixed(float+__complex__+a,+double+__complex__+b)+%7B%0A++++return+a+/+b%3B+//+This+should+warn+but+it+doesn!'t.%0A%7D%0A%0Adouble+__complex__+div_mixed(int+__complex__+a,+double+__complex__+b)+%7B%0A++++return+a+/+b%3B+//+This+should+warn+but+it+doesn!'t.%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:30.958904109589042,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-target+aarch64-pc-windows-msvc+-fcomplex-arithmetic%3Dpromoted+-fsyntax-only+-Wno-unused-command-line-argument',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+(trunk)+(Editor+%231)',t:'0')),k:50,l:'4',m:50.60104694679994,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+(trunk)',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+(trunk)+(Compiler+%231)',t:'0')),header:(),l:'4',m:49.398953053200046,n:'0',o:'',s:0,t:'0')),k:69.04109589041096,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWE9v67gR_zT0hZAhUX8sHXyI7M2pu6_obrvHgBJHEt9SpEBSdvLtC5KyYyXpq7N9xcMChm0OZzjz4_yVqDG8lwB7lNcoP27obAel9z9TsCfgZtMo9rL_bQCMijj6feD9ADqaNLTccCWjTumoVeMk4Dli_OSJqIgxjNxaYPg8gPSi3YWLam6HESxvUXqctBqVBeZE1GS5kpgbPBtgmEqG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