You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang][Sema] Fix crash when diagnosing near-match for 'constexpr' redeclaration in C++11 (#92452)
Clang crashes when diagnosing the following invalid redeclaration in
C++11:
```
struct A {
void f();
};
constexpr void A::f() { } // crash here
```
This happens because `DiagnoseInvalidRedeclaration` tries to create a
fix-it to remove `const` from the out-of-line declaration of `f`, but
there is no `SourceLocation` for the `const` qualifier (it's implicitly
`const` due to `constexpr`) and an assert in
`FunctionTypeInfo::getConstQualifierLoc` fails.
This patch changes `DiagnoseInvalidRedeclaration` to only suggest the removal of the
`const` qualifier when it was explicitly specified in the _cv-qualifier-seq_ of the declaration.
Copy file name to clipboardExpand all lines: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -154,3 +154,14 @@ namespace {
154
154
// FIXME: We should diagnose this prior to C++17.
155
155
constint &r = A::n;
156
156
}
157
+
158
+
#if __cplusplus < 201402L
159
+
namespaceImplicitConstexprDef {
160
+
structA {
161
+
voidf(); // expected-note {{member declaration does not match because it is not const qualified}}
162
+
};
163
+
164
+
constexprvoidA::f() { } // expected-warning {{'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior}}
165
+
// expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'ImplicitConstexprDef::A'}}
0 commit comments