Skip to content

Commit db8fd33

Browse files
giulianobelinassiShivam Gupta
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 f8e8897 commit db8fd33

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
@@ -1739,6 +1739,7 @@ def RegCall : DeclOrTypeAttr {
17391739
}
17401740

17411741
def Final : InheritableAttr {
1742+
let CanPrintOnLeft = 0;
17421743
let Spellings = [CustomKeyword<"final">, CustomKeyword<"sealed">];
17431744
let Accessors = [Accessor<"isSpelledAsSealed", [CustomKeyword<"sealed">]>];
17441745
let SemaHandler = 0;
@@ -2692,6 +2693,7 @@ def Overloadable : Attr {
26922693
}
26932694

26942695
def Override : InheritableAttr {
2696+
let CanPrintOnLeft = 0;
26952697
let Spellings = [CustomKeyword<"override">];
26962698
let SemaHandler = 0;
26972699
// 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)