Sirui Mu 3c4e730802
[Sema][clangd] add noexcept to override functions during code completion (#75937)
If a virtual function is declared with `noexcept`, functions that
override this function in the derived classes must be declared with
`noexcept` as well. This PR updates code completion in clang Sema. It
adds `noexcept` specifier to override functions in the code completion
result if the functions override a `noexcept` virtual function.
2025-06-28 14:37:20 +08:00

58 lines
2.1 KiB
C++

class A {
public:
virtual void vfunc(bool param);
virtual void vfunc(bool param, int p);
void func(bool param);
};
class B : public A {
virtual int ttt(bool param, int x = 3) const;
void vfunc(bool param, int p) override;
};
class C : public B {
public:
void vfunc(bool param) override;
vf;
};
// Runs completion at ^vf
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-4):3 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: COMPLETION: Pattern : int ttt(bool param, int x = 3) const override{{$}}
// CHECK-CC1: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
// CHECK-CC1-NOT: COMPLETION: Pattern : void vfunc(bool param) override{{$}}
//
// Runs completion at vf^
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-10):5 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2-NOT: COMPLETION: Pattern : int ttt(bool param, int x = 3) const override{{$}}
// CHECK-CC2: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
// CHECK-CC2-NOT: COMPLETION: Pattern : void vfunc(bool param) override{{$}}
//
// Runs completion at void ^ on line 13.
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-17):8 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
// CHECK-CC3-NOT: COMPLETION: Pattern : int ttt(bool param, int x = 3) const override{{$}}
// CHECK-CC3-NOT: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
// CHECK-CC3-NOT: COMPLETION: Pattern : void vfunc(bool param) override{{$}}
void func() {
class D : public A {
};
}
// Runs completion at empty line on line 37.
// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-5):1 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
class NoexceptBase {
public:
virtual void method() noexcept;
};
class NoexceptDerived : public NoexceptBase {
public:
met;
};
// Runs completion at met^ in the body of NoexceptDerived.
// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-4):6 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
// CHECK-CC5: COMPLETION: Pattern : void method() noexcept override{{$}}