llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: gtrong
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/208868.diff
2 Files Affected:
- (modified) clang/lib/Parse/ParseDecl.cpp (+3-2)
- (added) clang/test/SemaCXX/default-arg-error-recovery.cpp (+11)
``````````diff
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/SemaCXX/default-arg-error-recovery.cpp
b/clang/test/SemaCXX/default-arg-error-recovery.cpp
new file mode 100644
index 0000000000000..77d49cd818d4b
--- /dev/null
+++ b/clang/test/SemaCXX/default-arg-error-recovery.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+
+struct S {};
+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<S>(e1) == 42, ""); // expected-error {{no matching function
for call to 'foo'}}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/208868
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits