Author: gtrong
Date: 2026-07-14T07:48:26Z
New Revision: 94b7d2b4d8d7c8cfa2d09a6aa2bb1d7df81d047c

URL: 
https://github.com/llvm/llvm-project/commit/94b7d2b4d8d7c8cfa2d09a6aa2bb1d7df81d047c
DIFF: 
https://github.com/llvm/llvm-project/commit/94b7d2b4d8d7c8cfa2d09a6aa2bb1d7df81d047c.diff

LOG: [Clang] Fix error recovery for default arguments (#208868)

Fixes  #205718 
### Description
This PR fixes an issue where Clang incorrectly skips the creation of a
parameter when an error occurs in a default argument that involves a GNU
statement expression (`({ ... })`).

Previously, if the default expression evaluation failed within a
statement expression, the error recovery was not handled properly,
leading to the parameter being dropped. This fix ensures that the
parameter is correctly created and error recovery proceeds as expected.



### Testing
Added/Updated test cases in
`clang/test/SemaCXX/default-arg-error-recovery.cpp` to cover invalid
default arguments inside statement expressions.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/Parse/ParseDecl.cpp
    clang/test/Parser/cxx-default-args.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 4dc7b609ca5c5..9063e54b3e692 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1230,6 +1230,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 a 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 e71f7e1b2d62c..88f07bb104fcb 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7806,9 +7806,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@-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'}}
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to