Skip to content

Commit 53705dd

Browse files
authored
[clang]improve diagnosing redefined defaulted constructor with different exception specs (#69688)
1 parent 2dea7bd commit 53705dd

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ Improvements to Clang's diagnostics
348348
| ~~~~~~~~~^~~~~~~~
349349
- Clang now always diagnoses when using non-standard layout types in ``offsetof`` .
350350
(`#64619: <https://github.com/llvm/llvm-project/issues/64619>`_)
351+
- Clang now diagnoses redefined defaulted constructor when redefined
352+
defaulted constructor with different exception specs.
353+
(`#69094: <https://github.com/llvm/llvm-project/issues/69094>`_)
351354
- Clang now diagnoses use of variable-length arrays in C++ by default (and
352355
under ``-Wall`` in GNU++ mode). This is an extension supported by Clang and
353356
GCC, but is very easy to accidentally use without realizing it's a

clang/lib/Sema/SemaDecl.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,18 +3922,6 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
39223922
}
39233923

39243924
if (getLangOpts().CPlusPlus) {
3925-
// C++1z [over.load]p2
3926-
// Certain function declarations cannot be overloaded:
3927-
// -- Function declarations that differ only in the return type,
3928-
// the exception specification, or both cannot be overloaded.
3929-
3930-
// Check the exception specifications match. This may recompute the type of
3931-
// both Old and New if it resolved exception specifications, so grab the
3932-
// types again after this. Because this updates the type, we do this before
3933-
// any of the other checks below, which may update the "de facto" NewQType
3934-
// but do not necessarily update the type of New.
3935-
if (CheckEquivalentExceptionSpec(Old, New))
3936-
return true;
39373925
OldQType = Context.getCanonicalType(Old->getType());
39383926
NewQType = Context.getCanonicalType(New->getType());
39393927

@@ -4055,6 +4043,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
40554043
}
40564044
}
40574045

4046+
// C++1z [over.load]p2
4047+
// Certain function declarations cannot be overloaded:
4048+
// -- Function declarations that differ only in the return type,
4049+
// the exception specification, or both cannot be overloaded.
4050+
4051+
// Check the exception specifications match. This may recompute the type of
4052+
// both Old and New if it resolved exception specifications, so grab the
4053+
// types again after this. Because this updates the type, we do this before
4054+
// any of the other checks below, which may update the "de facto" NewQType
4055+
// but do not necessarily update the type of New.
4056+
if (CheckEquivalentExceptionSpec(Old, New))
4057+
return true;
4058+
40584059
// C++11 [dcl.attr.noreturn]p1:
40594060
// The first declaration of a function shall specify the noreturn
40604061
// attribute if any declaration of that function specifies the noreturn
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++11 %s
2+
3+
struct ExplicitlySpecialMethod {
4+
ExplicitlySpecialMethod() = default;
5+
};
6+
ExplicitlySpecialMethod::ExplicitlySpecialMethod() {} // expected-error{{definition of explicitly defaulted default constructor}}
7+
8+
struct ImplicitlySpecialMethod {};
9+
ImplicitlySpecialMethod::ImplicitlySpecialMethod() {} // expected-error{{definition of implicitly declared default constructor}}

0 commit comments

Comments
 (0)