================
@@ -452,6 +452,124 @@ template <typename U, bool>
 inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
 )cpp",
           ""},
+      // C++11 attribute list
+      {
+          R"cpp(
+            struct A {
+              [ [nodiscard, deprecated("no")] ] int ^foo() { return 0; }
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              [ [nodiscard, deprecated("no")] ] int foo() ;
+            };
+)cpp",
+          "int A::foo() { return 0; }\n"},
+      // GNU attribute list
+      {
+          R"cpp(
+            struct A {
+              __attribute__((noinline, annotate("bar"))) int ^foo() { return 
0; }
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              __attribute__((noinline, annotate("bar"))) int foo() ;
+            };
+)cpp",
+          "int A::foo() { return 0; }\n"},
+      // Attribute at the end of the function declarator
+      {
+          R"cpp(
+            struct A {
+              int ^foo() __attribute__((noinline)) { return 0; }
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              int foo() __attribute__((noinline)) ;
+            };
+)cpp",
+          "int A::foo() { return 0; }\n"},
+      // Mixed attributes
+      {
+          R"cpp(
+            struct A {
+              __attribute__((noinline)) [ [nodiscard] ] int ^foo() { return 0; 
}
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              __attribute__((noinline)) [ [nodiscard] ] int foo() ;
+            };
+)cpp",
+          "int A::foo() { return 0; }\n"},
+      // Attributes with namespaces
+      {
+          R"cpp(
+            struct A {
+              [ [clang::noinline] ] int ^foo() { return 0; }
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              [ [clang::noinline] ] int foo() ;
+            };
+)cpp",
+          "int A::foo() { return 0; }\n"},
+      {
+          R"cpp(
+            struct A {
+              [ [using clang: noinline, annotate("x")] ] int ^foo() { return 
0; }
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              [ [using clang: noinline, annotate("x")] ] int foo() ;
+            };
+)cpp",
+          "int A::foo() { return 0; }\n"},
+      // Unknown attributes (not part of the AST, so they are not removed)
+      {
+          R"cpp(
+            struct A {
+              [ [unknown] ] int ^foo() { return 0; }
+            };
+)cpp",
+          R"cpp(
+            struct A {
+              [ [unknown] ] int foo() ;
+            };
+)cpp",
+          "[ [unknown] ] int A::foo() { return 0; }\n"},
+      // Unknown and known attribute in one list
+      {
+          R"cpp(
+            struct A {
+              [ [unknown, nodiscard] ] int ^foo() { return 0; }
----------------
ckandeler wrote:

**[LLM-generated]** This test shows that the unknown attribute *is* removed 
when it shares a `[[...]]` list with a known one, because the whole group gets 
deleted. That's probably fine, but it contradicts the statement in the PR 
description / commit message that attributes unknown to clang are not removed. 
It would be worth wording that limitation more precisely (e.g. "attribute 
groups containing only unknown attributes are kept").

https://github.com/llvm/llvm-project/pull/242635
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to