Skip to content

Commit e3c832b

Browse files
giulianobelinassitstellar
authored andcommitted
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 <[email protected]>
1 parent 1deeee3 commit e3c832b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ def RegCall : DeclOrTypeAttr {
15901590
}
15911591

15921592
def Final : InheritableAttr {
1593+
let CanPrintOnLeft = 0;
15931594
let Spellings = [CustomKeyword<"final">, CustomKeyword<"sealed">];
15941595
let Accessors = [Accessor<"isSpelledAsSealed", [CustomKeyword<"sealed">]>];
15951596
let SemaHandler = 0;
@@ -2472,6 +2473,7 @@ def Overloadable : Attr {
24722473
}
24732474

24742475
def Override : InheritableAttr {
2476+
let CanPrintOnLeft = 0;
24752477
let Spellings = [CustomKeyword<"override">];
24762478
let SemaHandler = 0;
24772479
// Omitted from docs, since this is language syntax, not an attribute, as far
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file contain tests to check if override and final are dumped in the
2+
// correct positions.
3+
4+
// RUN: %clang_cc1 -ast-print -x c++ %s -o - | FileCheck %s
5+
6+
// CHECK: class A {
7+
class A {
8+
// CHECK-NEXT: virtual void f();
9+
virtual void f();
10+
11+
// CHECK-NEXT: virtual void g() final;
12+
virtual void g() final;
13+
} AA;
14+
15+
// CHECK: class B : public A {
16+
class B : public A {
17+
// CHECK-NEXT: virtual void f() override {
18+
virtual void f() override {
19+
};
20+
} B;

0 commit comments

Comments
 (0)