<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 - 'nodiscard' can be applied to function pointers"
   href="https://bugs.llvm.org/show_bug.cgi?id=45520">45520</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>'nodiscard' can be applied to function pointers
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang, gcc, and cl disagree on the diagnostics for the code below:

<a href="https://godbolt.org/z/-zaSRh">https://godbolt.org/z/-zaSRh</a>

[[nodiscard]] bool (*f)();

void _(){
  f();
}


clang:
<source>:4:3: warning: ignoring return value of function declared with
'nodiscard' attribute [-Wunused-result]

  f();

  ^

1 warning generated.

Compiler returned: 0

gcc:
<source>:1:25: warning: 'nodiscard' attribute can only be applied to functions
or to class or enumeration types [-Wattributes]

    1 | [[nodiscard]] bool (*f)();

      |                         ^

Compiler returned: 0

cl:
example.cpp

Compiler returned: 0



Looking at the standard I would think that gcc's behavior is correct?
<a href="http://eel.is/c++draft/dcl.attr.nodiscard#1.sentence-1">http://eel.is/c++draft/dcl.attr.nodiscard#1.sentence-1</a>
"The attribute-token nodiscard may be applied to the declarator-id in a
function declaration or to the declaration of a class or enumeration."</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>