[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue May 27 04:28:05 PDT 2025
================
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -Wunknown-attributes -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wunknown-attributes -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+[[gmu::deprected]] // expected-warning {{unknown attribute 'gmu::deprected' ignored; did you mean 'gnu::deprecated'?}}
+int f1(void) {
+ return 0;
+}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:17}:"gnu::deprecated"
+
+[[gmu::deprecated]] // expected-warning {{unknown attribute 'gmu::deprecated' ignored; did you mean 'gnu::deprecated'?}}
+int f2(void) {
+ return 0;
+}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:18}:"gnu::deprecated"
+
+[[gnu::deprected]] // expected-warning {{unknown attribute 'gnu::deprected' ignored; did you mean 'gnu::deprecated'?}}
+int f3(void) {
+ return 0;
+}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:17}:"gnu::deprecated"
+
+[[deprected]] // expected-warning {{unknown attribute 'deprected' ignored; did you mean 'deprecated'?}}
+int f4(void) {
+ return 0;
+}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:12}:"deprecated"
+
+[[using gnu : deprected]] // expected-warning {{unknown attribute 'gnu::deprected' ignored; did you mean 'gnu::deprecated'?}}
+int f5(void) {
+ return 0;
+}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:24}:"gnu::deprecated"
----------------
AaronBallman wrote:
I think this shows a bug with the patch because this seems to be replacing `[[using gnu: deprected]]` with `[[gnu::deprecated]]`. While this is 1:1 in this example, consider something like: `[[using gnu: deprected, noreturn]]` where there are multiple attributes all sharing the same prefix.
I think `using` should be handled in a separate patch; for this PR, I'd recommend not attempting to fix this situation. But we may not have that information in Sema, so that may be more involved.
https://github.com/llvm/llvm-project/pull/141305
More information about the cfe-commits
mailing list