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

    <tr>
        <th>Summary</th>
        <td>
            No diagnostic is reported for illegal macro definitions such as "noreturn" and "carries_dependency"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          romanova-ekaterina
      </td>
    </tr>
</table>

<pre>
    Consider the testcase like that:

#define override 1 
#define noreturn 2
#define final 3 
#define carries_dependency 4

int foo(int a)
{
  return (a == override + noreturn + final + carries_dependency);
}


When compiling it with clang compiler, I see that the diagnostic is issued for 2 out 4 macros (override and final), which is inconsistent.
 
I could see the argument why no error should be reported. I could see an argument why all four errors should be reported. But not reporting diagnostic only for 2 out of 4 macros that falls into the same category is suprising.


(note: the same behavior happens with c++14, c++17, c++20 standard)

clang -c -Wpedantic -Wall -std=c++11 test.cpp
test.cpp:2:9: warning: keyword is hidden by macro definition [-Wkeyword-macro]
#define override 1
 ^
test.cpp:4:9: warning: keyword is hidden by macro definition [-Wkeyword-macro]
#define final 3
        ^
2 warnings generated.


=======================

On one hand, https://eel.is/c++draft/macro.names#2 says:
"A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 4, or to the attribute-tokens described in [dcl.attr], except that the names likely and unlikely may be defined as function-like macros ([cpp.replace]).
"Table 4" is: "final import module override".
Redefining attribute-tokens is also not allowed.
https://eel.is/c++draft/dcl.attr; "carries_dependency" and "noreturn" are both in there (attribute tokens).

The use of the language "shall not" means that the program is ill-formed and requires a diagnostic, according to cppreference.

On the other hand, it might be considered as and undefined bahavior.
There is a 10 years old thread on llvm.org explaining why error should not be reported.
[However, it doesn't address my inconsistency question]
https://lists.llvm.org/pipermail/cfe-dev/2013-June/030283.html


Summary:
If Clang diagnoses a redefinition some attribute names such as "final" and "override", then failing to do so for "carries_dependency" and "noreturn" seems like a Clang bug.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VkFv4zYT_TX0ZWBBpux1fPAhjr_g2x5aoF0gx2JEjiQ2FKklqXj17wtSki0nKdCiaBDIosghZ957M0P0XtWG6Mh2J7Y7r7APjXVHZ1s09g3X9IqBnDK4Kq0cjk_WeCXJQWgIAvkg0BNo9UoQGgyseGT5meXzkxeSKmUI7Bs5pyTBBt5PGeso9M4Afz9TKYMaig8WAp1T5H-X1JGRZMQA2-WxygSorGX8Ib4h44dpdn8aXwCmIxl_QGDFmRXnm4uMn25OxcHoR3z7eHLcvDjN-5_vok_Pl4YMCNt2SitTgwpwUaEBodHU03dyjD_BV_A0opjAlQprY31QApQH5X1PEirrgIPtA2yhReGsjyFcPUcjR2ejV_wJLo0STTI3IhLnA5mQTRiMP19B2F7L6WwCdHXfkglwaQYwFsg568A3aVFJ4KizLpDMYGmJ5t4QtYbK9m4095_an_oAxobpS8RmEbI1elhEa6tbwAmhCrWOYQWbvPbYRlkEqq0bYsC-75zyytTZR0YYfzA2ECseb7YlNfimrIMGu46Mn0hi_MT4abONYM6D_WLAc_ABjUQnbypLz5HftYD1S0cSTQxq_RJxWfsgWXGet9ukNMpE142G11HxyFnxeIhuXtAZZer4-krDxToZY2yUlGSgHEZkIGWHCsoaYLvT-mVauk6zbHf-65ycFbH73wcftv-tD1OKz2k5_l394POpHmoy5DAK5xNCUwL_2__Fhr8YsIagQSMj2U0InY-ljT8z_kykM-UZf54YlA6rwPhzCjEz2JJnvODgcfC3esj5IwSHxmtM6PRGBfBNFERMggUrLg56I6mCtBlo-qEEaj2AkhSFhBqCnVnw0cMpDcb5SpHzoGO2S1AGvmGpCZKGrZuXYghOlX2gdbCvUfCSvHCqHE3Y7iSFzuKiSBp_AvohqAu38jS5pl5JD6nu9GYatDjERB_DkYAeqt6IGPQ69Ylb3WK7k-i6zFGnUVA66JBd8bq6zUFFIIFxPspFtbFiQGtlr28yZpxPxr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