Skip to content

Commit

Permalink
Fix override keyword being print to the left side
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
giulianobelinassi authored and tstellar committed Apr 16, 2024
1 parent 1deeee3 commit e3c832b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions clang/test/AST/ast-dump-override-final.cpp
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e3c832b

Please sign in to comment.