r369033 - Allow standards-based attributes to have leading and trailing underscores.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 11:35:45 PDT 2019
Author: aaronballman
Date: Thu Aug 15 11:35:44 2019
New Revision: 369033
URL: http://llvm.org/viewvc/llvm-project?rev=369033&view=rev
Log:
Allow standards-based attributes to have leading and trailing underscores.
This gives library implementers a way to use standards-based attributes that do not conflict with user-defined macros of the same name. Attributes in C2x require this behavior normatively (C2x 6.7.11p4), but there's no reason to not have the same behavior in C++, especially given that such attributes may be used by a C library consumed by a C++ compilation.
Modified:
cfe/trunk/lib/Sema/ParsedAttr.cpp
cfe/trunk/test/Preprocessor/has_attribute.cpp
cfe/trunk/test/Preprocessor/has_c_attribute.c
cfe/trunk/test/Sema/attr-cx2.c
cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
Modified: cfe/trunk/lib/Sema/ParsedAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParsedAttr.cpp?rev=369033&r1=369032&r2=369033&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ParsedAttr.cpp (original)
+++ cfe/trunk/lib/Sema/ParsedAttr.cpp Thu Aug 15 11:35:44 2019
@@ -125,7 +125,8 @@ static StringRef normalizeAttrName(Strin
SyntaxUsed == ParsedAttr::AS_GNU ||
((SyntaxUsed == ParsedAttr::AS_CXX11 ||
SyntaxUsed == ParsedAttr::AS_C2x) &&
- (NormalizedScopeName == "gnu" || NormalizedScopeName == "clang"));
+ (NormalizedScopeName.empty() || NormalizedScopeName == "gnu" ||
+ NormalizedScopeName == "clang"));
if (ShouldNormalize && AttrName.size() >= 4 && AttrName.startswith("__") &&
AttrName.endswith("__"))
AttrName = AttrName.slice(2, AttrName.size() - 2);
Modified: cfe/trunk/test/Preprocessor/has_attribute.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.cpp?rev=369033&r1=369032&r2=369033&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_attribute.cpp (original)
+++ cfe/trunk/test/Preprocessor/has_attribute.cpp Thu Aug 15 11:35:44 2019
@@ -31,6 +31,9 @@ __clang__::fallthrough: __has_cpp_attrib
// CHECK: _Clang::fallthrough: 201603L
CXX11(_Clang::fallthrough)
+// CHECK: __nodiscard__: 201907L
+CXX11(__nodiscard__)
+
// CHECK: __gnu__::__const__: 1
CXX11(__gnu__::__const__)
Modified: cfe/trunk/test/Preprocessor/has_c_attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_c_attribute.c?rev=369033&r1=369032&r2=369033&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_c_attribute.c (original)
+++ cfe/trunk/test/Preprocessor/has_c_attribute.c Thu Aug 15 11:35:44 2019
@@ -10,3 +10,7 @@
int does_not_have_selectany();
#endif
+// CHECK: has_nodiscard_underscore
+#if __has_c_attribute(__nodiscard__)
+ int has_nodiscard_underscore();
+#endif
Modified: cfe/trunk/test/Sema/attr-cx2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-cx2.c?rev=369033&r1=369032&r2=369033&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-cx2.c (original)
+++ cfe/trunk/test/Sema/attr-cx2.c Thu Aug 15 11:35:44 2019
@@ -24,3 +24,6 @@ void foo2(void) [[clang::unavailable("no
void bar(void) {
foo2(); // expected-error {{'foo2' is unavailable: not available - replaced}}
}
+
+[[nodiscard]] int without_underscores(void);
+[[__nodiscard__]] int underscores(void);
Modified: cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-cxx0x.cpp?rev=369033&r1=369032&r2=369033&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-cxx0x.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-cxx0x.cpp Thu Aug 15 11:35:44 2019
@@ -46,7 +46,7 @@ static_assert(alignof(outer<int,char>::i
static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-error{{invalid application of 'alignof' to a function type}}
-[[__carries_dependency__]] // expected-warning{{unknown attribute '__carries_dependency__' ignored}}
+[[__carries_dependency__]]
void func(void);
alignas(4) auto PR19252 = 0;
More information about the cfe-commits
mailing list