Skip to content

[clang][Sema] deleted overriding function can have lax except spec #76248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ C++2c Feature Support
Resolutions to C++ Defect Reports
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Implemented `CWG1351 <https://cplusplus.github.io/CWG/issues/1351.html>`_ which allows lax exception specifications on
overriding functions that are explicitly defined to be deleted.

C Language Changes
------------------
- ``structs``, ``unions``, and ``arrays`` that are const may now be used as
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaExceptionSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,11 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
if (isa<CXXDestructorDecl>(New) && New->getParent()->isDependentType())
return false;

// CWG1351: if the overriding function is defined as deleted, we don't need
// this check.
if (New->isDeleted())
return false;

// If the old exception specification hasn't been parsed yet, or the new
// exception specification can't be computed yet, remember that we need to
// perform this check when we get to the end of the outermost
Expand Down
16 changes: 14 additions & 2 deletions clang/test/CXX/drs/dr13xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ namespace dr1347 { // dr1347: 3.1
#endif
}

namespace dr1351 { // dr1351: 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you intended // dr1351: 18.

#if __cplusplus >= 201103L
struct Base {
virtual void method() noexcept = delete;
};

struct Derived : Base {
void method() override = delete;
};
#endif
}

namespace dr1358 { // dr1358: 3.1
#if __cplusplus >= 201103L
struct Lit { constexpr operator int() const { return 0; } };
Expand Down Expand Up @@ -425,7 +437,7 @@ namespace dr1359 { // dr1359: 3.5
union B { constexpr B() = default; int a; }; // #dr1359-B
// cxx11-17-error@-1 {{defaulted definition of default constructor is not constexpr}}
union C { constexpr C() = default; int a, b; }; // #dr1359-C
// cxx11-17-error@-1 {{defaulted definition of default constructor is not constexpr}}
// cxx11-17-error@-1 {{defaulted definition of default constructor is not constexpr}}
struct X { constexpr X() = default; union {}; };
// since-cxx11-error@-1 {{declaration does not declare anything}}
struct Y { constexpr Y() = default; union { int a; }; }; // #dr1359-Y
Expand Down Expand Up @@ -645,7 +657,7 @@ struct A {
} // namespace dr1397

namespace dr1399 { // dr1399: dup 1388
template<typename ...T> void f(T..., int, T...) {} // #dr1399-f
template<typename ...T> void f(T..., int, T...) {} // #dr1399-f
// cxx98-error@-1 {{variadic templates are a C++11 extension}}
void g() {
f(0);
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CXX/except/except.spec/p5-virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct Base
virtual void f15();
virtual void f16();

virtual void f17() noexcept = delete;

virtual void g1() throw(); // expected-note {{overridden virtual function is here}}
virtual void g2() throw(int); // expected-note {{overridden virtual function is here}}
virtual void g3() throw(A); // expected-note {{overridden virtual function is here}}
Expand Down Expand Up @@ -81,6 +83,8 @@ struct Derived : Base
virtual void f15() noexcept;
virtual void f16() throw();

virtual void f17() = delete;

virtual void g1() throw(int); // expected-error {{exception specification of overriding function is more lax}}
virtual void g2(); // expected-error {{exception specification of overriding function is more lax}}
virtual void g3() throw(D); // expected-error {{exception specification of overriding function is more lax}}
Expand Down