diff options
author | Giuliano Belinassi <gbelinassi@suse.de> | 2024-04-11 20:09:49 -0300 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2024-04-16 16:09:49 -0700 |
commit | e3c832b37b0a7b97eb16eaff2dda747093a858e2 (patch) | |
tree | c59ba73fe6c0b9b2164f21ddb87f7c8c02831f19 | |
parent | 1deeee3f5da4f323e0e5b33688450dc066e9651b (diff) | |
download | llvm-e3c832b37b0a7b97eb16eaff2dda747093a858e2.zip llvm-e3c832b37b0a7b97eb16eaff2dda747093a858e2.tar.gz llvm-e3c832b37b0a7b97eb16eaff2dda747093a858e2.tar.bz2 |
Fix override keyword being print to the left side
Previously, the `override` keyword in C++ was being print in the left
side of a method decl, which is unsupported by C++ standard. This commit
fixes that by setting the `CanPrintOnLeft` field to 0, forcing it to be
print on the right side of the decl.
Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
-rw-r--r-- | clang/include/clang/Basic/Attr.td | 2 | ||||
-rw-r--r-- | clang/test/AST/ast-dump-override-final.cpp | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 58838b0..dbf2dd2 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1590,6 +1590,7 @@ def RegCall : DeclOrTypeAttr { } def Final : InheritableAttr { + let CanPrintOnLeft = 0; let Spellings = [CustomKeyword<"final">, CustomKeyword<"sealed">]; let Accessors = [Accessor<"isSpelledAsSealed", [CustomKeyword<"sealed">]>]; let SemaHandler = 0; @@ -2472,6 +2473,7 @@ def Overloadable : Attr { } def Override : InheritableAttr { + let CanPrintOnLeft = 0; let Spellings = [CustomKeyword<"override">]; let SemaHandler = 0; // Omitted from docs, since this is language syntax, not an attribute, as far diff --git a/clang/test/AST/ast-dump-override-final.cpp b/clang/test/AST/ast-dump-override-final.cpp new file mode 100644 index 0000000..c1cee6b --- /dev/null +++ b/clang/test/AST/ast-dump-override-final.cpp @@ -0,0 +1,20 @@ +// This file contain tests to check if override and final are dumped in the +// correct positions. + +// RUN: %clang_cc1 -ast-print -x c++ %s -o - | FileCheck %s + +// CHECK: class A { +class A { + // CHECK-NEXT: virtual void f(); + virtual void f(); + + // CHECK-NEXT: virtual void g() final; + virtual void g() final; +} AA; + +// CHECK: class B : public A { +class B : public A { + // CHECK-NEXT: virtual void f() override { + virtual void f() override { + }; +} B; |