<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Optional Parameter Argument Preprocessor trick fails for objc_method_family (init) methods"
   href="https://bugs.llvm.org/show_bug.cgi?id=45245">45245</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Optional Parameter Argument Preprocessor trick fails for objc_method_family (init) methods
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dmaclach@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23256" name="attach_23256" title="Code for repro case.">attachment 23256</a> <a href="attachment.cgi?id=23256&action=edit" title="Code for repro case.">[details]</a></span>
Code for repro case.

There is a "trick" described at
<a href="https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros">https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros</a>
for doing optional parameters with c macros.

It is used by the popular <a href="https://ocmock.org/">https://ocmock.org/</a> library.

Unfortunately it seems to generate a warning for unused-value that it shouldn't
generate when used with an objc_method_family (init) from within an objc method
implementation.

To repro:

Xcode 11.3 (or Xcode 11.4b3)

clang -Werror -Wunused-value -fobjc-arc main.m

Expected Result: Clean compile
Actual Result:

main.m:30:13: error: expression result unused [-Werror,-Wunused-value]
  OCMVerify([object init]);
            ^~~~~~~~~~~~~
main.m:12:64: note: expanded from macro 'OCMVerify'
#define OCMVerify(...) _OCMVerify_X(,##__VA_ARGS__, _OCMVerify(__VA_ARGS__))
                                                               ^~~~~~~~~~~
main.m:8:5: note: expanded from macro '_OCMVerify'
    invocation; \
    ^~~~~~~~~~
main.m:11:39: note: expanded from macro '_OCMVerify_X'
#define _OCMVerify_X(x,A,FUNC, ...)   FUNC</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>