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

    <tr>
        <th>Summary</th>
        <td>
            [clang] __has_extension changes semantics based on -pedantic-errors
        </td>
    </tr>

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

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

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

<pre>
    I just found this in `clang/docs/LanguageExtensions.rst:143`:

> If the `-pedantic-errors option is given, __has_extension` is equivalent to `__has_feature`.

And in `clang/lib/Lex/PPMacroExpansion.cpp:1161`:

```
static bool HasExtension(const Preprocessor &PP, StringRef Extension) {
  if (HasFeature(PP, Extension))
    return true;

  // If the use of an extension results in an error diagnostic, extensions are
  // effectively unavailable, so just return false here.
  if (PP.getDiagnostics().getExtensionHandlingBehavior() >=
 diag::Severity::Error)
    return false;

  const LangOptions &LangOpts = PP.getLangOpts();

  ...
```

So basically, `__has_extension(...)` always returns `0` when `-pedantic-errors` is used. This means that the semantics of programs can actually depend on whether `-pedantic-errors` is passed, which seems really confusing because few people would expect compiler diagnostics to impact semantics. For example, it is possible to end up in a situation where ODR is violated (via a `#if __has_extension(...)` check) based solely on whether `-pedantic-errors` is passed, which illustrates very well why this is undesirable.

This led to e.g. the issue fixed in #84065, and more discussion is available on that review.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU2P2zgP_jXKhRjDlvPlQw4zbyZogXfRoN17QUu0ra4ieUXZSf79QnYmTaeDPSxgOLDCj4d8HlLIbFpHtBOrF7HaL3CInQ87q413jha119fdZ_gxcITGD05D7AyDcSDWubLoWiEP2isW8vB_dO2ALb1eIjk23nEWOIryuViWYp2L8lnke5G_vctX-NxA7CiFeupJo4tGPVEIPjD4PhrvwDC0ZiQn5P_g-_cO-Tu9RRfrPP1Nfw9mREsuQvQp1GzWEMYhkF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