Issue 180740
Summary C++17: Macro named ‘deprecated’ compiles without diagnostic
Labels new issue
Assignees
Reporter vrukesh
    **What code / commands /steps will reproduce the problem?**
Compile the below sample CPP code for C++17 standard.

`
#define deprecated 10

int main() {
    return deprecated;
}
`
Godbolt compile explorer link: https://godbolt.org/z/z8KPoqYeq

**What is the expected result?**
Since, the code defines a macro `deprecated` which is an attribute token, and compiles with clang++ -std=c++17 , code must throw diagnostic error or warning.


As per C++14 Standard (ISO/IEC 14882:2014),

_A translation unit that includes a standard library header shall not #define or #undef names declared in any standard library header.
A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 3, or to the attribute-tokens described in 7.6._

**Content of keywords listed in table:** alignas, alignof, asm, auto, bool, break, case, catch, char, char16_t, char32_t, class, const, constexpr, const_cast, 2, continue, decltype, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, noexcept, nullptr, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_assert, static_cast, struct, switch, template, this, thread_local, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while.


**7.6.5 Deprecated attribute**
[dcl.attr.deprecated]
The attribute-token deprecated can be used to mark names and entities whose use is still allowed, but is discouraged for some reason. [ Note: in particular, deprecated is appropriate for names and entities that are deemed obsolescent or unsafe. — end note ] It shall appear at most once in each attribute-list. An attribute-argument-clause may be present and, if present, it shall have the form: 
( string-literal )

**What happens instead?**
A program that defines a macro `deprecated` and returns it compiles cleanly with clang++ -std=c++17

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to