Issue 92196
Summary No diagnostic is reported for illegal macro definitions such as "noreturn" and "carries_dependency"
Labels new issue
Assignees
Reporter romanova-ekaterina
    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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to