[clang] [Clang] Fix error recovery for default arguments (PR #208868)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 13 18:54:19 PDT 2026
https://github.com/gtrong updated https://github.com/llvm/llvm-project/pull/208868
>From 60838aa7665a59f292b6c864ee4a75d68df37c7d Mon Sep 17 00:00:00 2001
From: gtrong <1619664008 at qq.com>
Date: Fri, 10 Jul 2026 21:32:11 +0800
Subject: [PATCH 1/2] Backup my fixes before forcing LF
---
clang/docs/ReleaseNotes.md | 19 +++++++++++++++----
clang/lib/Parse/ParseDecl.cpp | 5 +++--
clang/test/Parser/cxx-default-args.cpp | 12 ++++++++++++
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index b7142ecb072ff..6da07990a1269 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1083,10 +1083,21 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
#### Crash and bug fixes
-- Fixed `security.VAList` checker producing false positives when analyzing
- C23 code where `va_start` expands to `__builtin_c23_va_start`.
-- Fixed a compiler crash when combining `_Atomic` and `__auto_type`
- in C, for example `_Atomic __auto_type x = expr`. (#GH118058)
+- Fixed the `security.VAList` checker producing false positives when analyzing C23 code where `va_start` expands to `__builtin_c23_va_start`. (#GH192024)
+- Fixed a crash when copying uninitialized data in a function named `swap`. (#GH178797)
+- Fixed a compiler crash when combining `_Atomic` and `__auto_type` in C, for example `_Atomic __auto_type x = expr`. (#GH118058)
+- Fixed a crash in the `unix.Malloc` checker when a function is annotated with both `ownership_returns` and `ownership_takes` (or `ownership_holds`). (#GH183344)
+- Fixed a crash in the `alpha.unix.cstring` checkers on zero-size element types (for example an empty struct in C). (#GH190457)
+- Fixed a use-after-free in `CheckerContext::getMacroNameOrSpelling`. (#GH194174)
+- Fixed a false positive in the `alpha.unix.cstring` checkers when the buffer argument points into the middle of an array, such as `memcpy(dst, &arr[i], size)`. (#GH198346)
+- Fixed the default binding of union aggregates being overwritten when initializing array elements with union members. (#GH178694)
+- The analyzer no longer rules out the equality of a pointer to the stack and a symbolic pointer in unknown space, because a function may return a pointer to some other stack frame (for example one received as an argument). (#GH187080)
+- Fixed the `getcwd` summary in the `unix.StdCLibraryFunctions` checker. (#GH175136)
+- Fixed invalid HTML nesting for popups at end of line. (#GH46089)
+- Fixed a false-positive in the `unix.BlockInCriticalSection` checker that reported double locking when using `std::lock_guard`/`std::unique_lock`/`std::scoped_lock`. (#GH208729)
+- Fixed a false-negative in the `unix.Malloc` checker due to a typo in the expected arguments of `if_nameindex`. It will now properly match its single expected argument. (#GH207726)
+- Fixed a crash in the Z3-solver-based (unsupported) constraint manager involving unary/binary operators. (#GH205037)
+- Fixed an crash where GNU statement expression syntax (`({ ... })`) caused arguments to disappear from parameter list. (#GH205718)
#### Improvements
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 3f41e7c5c6f0d..d31de39259c1a 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7777,9 +7777,10 @@ void Parser::ParseParameterDeclarationClause(
/*DefaultArg=*/nullptr);
// Skip the statement expression and continue parsing
SkipUntil(tok::comma, StopBeforeMatch);
- continue;
+ DefArgResult = ExprError();
+ } else {
+ DefArgResult = ParseAssignmentExpression();
}
- DefArgResult = ParseAssignmentExpression();
}
if (DefArgResult.isInvalid()) {
Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
diff --git a/clang/test/Parser/cxx-default-args.cpp b/clang/test/Parser/cxx-default-args.cpp
index 0a4dbe19d8d54..5e0fac22e9821 100644
--- a/clang/test/Parser/cxx-default-args.cpp
+++ b/clang/test/Parser/cxx-default-args.cpp
@@ -46,3 +46,15 @@ template <class T> void f();
template <> void f<int>(int = []{ ; return 0; }()) {} // expected-error{{no function template matches function template specialization 'f'}} \
// expected-note at -1{{candidate template ignored}}
}
+
+namespace GH208868 {
+struct Y {};
+enum E { e1, e2 };
+
+template<typename T>
+auto foo(E = ({ ; }) ? 0 : 1, E = e2) { // expected-error {{default argument may not use a GNU statement expression}}
+ return 42;
+}
+
+static_assert(foo<Y>(e1) == 42, ""); // expected-error {{no matching function for call to 'foo'}}
+}
>From b616b1ba752ecb4bd8789a2a7706e4683190d7ae Mon Sep 17 00:00:00 2001
From: gtrong <40399865+gtrong at users.noreply.github.com>
Date: Tue, 14 Jul 2026 09:54:10 +0800
Subject: [PATCH 2/2] Fix typo
---
clang/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 8c8ad3f10e8a8..223ea042886be 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1229,7 +1229,7 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
- Fixed a false-positive in the `unix.BlockInCriticalSection` checker that reported double locking when using `std::lock_guard`/`std::unique_lock`/`std::scoped_lock`. (#GH208729)
- Fixed a false-negative in the `unix.Malloc` checker due to a typo in the expected arguments of `if_nameindex`. It will now properly match its single expected argument. (#GH207726)
- Fixed a crash in the Z3-solver-based (unsupported) constraint manager involving unary/binary operators. (#GH205037)
-- Fixed an crash where GNU statement expression syntax (`({ ... })`) caused arguments to disappear from parameter list. (#GH205718)
+- Fixed a crash where GNU statement expression syntax (`({ ... })`) caused arguments to disappear from parameter list. (#GH205718)
#### Improvements
More information about the cfe-commits
mailing list