Skip to content

Commit 3333e12

Browse files
committed
[clang] add diagnose when member function contains invalid default argument
Fixed: #62122 This change pointer to add diagnose message for this code. ``` struct S { static int F(int n = 0 ? 0) { return 0; } }; ``` For default parameter, we should set it as unparsed even if meeting syntax error because it should be issued in real parser time instead of set is as invalid directly without diagnose. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D148372
1 parent f34ecb5 commit 3333e12

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ Bug Fixes in This Version
321321
(`#61885 <https://github.com/llvm/llvm-project/issues/61885>`_)
322322
- Clang constexpr evaluator now treats comparison of [[gnu::weak]]-attributed
323323
member pointer as an invalid expression.
324+
- Fix crash when member function contains invalid default argument.
325+
(`#62122 <https://github.com/llvm/llvm-project/issues/62122>`_)
324326

325327
Bug Fixes to Compiler Builtins
326328
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7381,13 +7381,9 @@ void Parser::ParseParameterDeclarationClause(
73817381
DefArgToks.reset(new CachedTokens);
73827382

73837383
SourceLocation ArgStartLoc = NextToken().getLocation();
7384-
if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
7385-
DefArgToks.reset();
7386-
Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
7387-
} else {
7388-
Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
7389-
ArgStartLoc);
7390-
}
7384+
ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument);
7385+
Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
7386+
ArgStartLoc);
73917387
} else {
73927388
// Consume the '='.
73937389
ConsumeToken();

clang/test/Parser/cxx-member-initializers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,9 @@ class G {
108108
// expected-error@-2 {{type name requires a specifier or qualifier}}
109109
// expected-error@-3 {{expected '>'}}
110110
// expected-note@-4 {{to match this '<'}}
111+
112+
void n(int x = 1 ? 2) {}
113+
// expected-error@-1 {{expected ':'}}
114+
// expected-note@-2 {{to match this '?'}}
115+
// expected-error@-3 {{expected expression}}
111116
};

0 commit comments

Comments
 (0)