<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 - No support for gcc "error" function attribute"
   href="https://bugs.llvm.org/show_bug.cgi?id=38091">38091</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>No support for gcc "error" function attribute
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>naruse@airemix.jp
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>GCC 4.3 supports "error" function attribute, but clang doesn't support it.
<a href="https://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/Function-Attributes.html#index-g_t_0040code_007berror_007d-function-attribute-2123">https://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/Function-Attributes.html#index-g_t_0040code_007berror_007d-function-attribute-2123</a>

Below description is why I want clang to implement this.

This attribute is similar to "diagnose_if" and "enable_if" function attribute.
But "error" function attribute behaves different and useful.

```c
int rb_scan_args_bad_format(const char *fmt,int ofs)
__attribute__((diagnose_if(fmt, "bad scan arg format","error")));

int
main(int argc, char **argv) {
    if (0) {
        rb_scan_args_bad_format("foo", 3);
    }
}
```

clang show error above code though the function call is optimized out.
But gcc successfully compiles below code.

```c
int rb_scan_args_bad_format(const char *fmt,int ofs)
    __attribute__((error("bad scan arg format")));

int
main(int argc, char **argv) {
    if (0) {
        rb_scan_args_bad_format("foo", 3);
    }
}
```

For example Ruby uses this feature in rb_scan_args.
<a href="https://github.com/ruby/ruby/blob/v2_5_1/include/ruby/ruby.h">https://github.com/ruby/ruby/blob/v2_5_1/include/ruby/ruby.h</a>
Its behavior is explained in
<a href="https://silverhammermba.github.io/emberb/c/#parsing-arguments">https://silverhammermba.github.io/emberb/c/#parsing-arguments</a>
Recent Ruby uses macros to implement it in order to handle its argument at
compile time.
And it uses "error" function attribute if its format argument is invalid.
In this use case, "error" function attribute's ignored if optimized out
behavior is very useful.

This is why I want clang also implement "error" function attribute.</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>