[clang] Fix crash with invalid member function param list (PR #139595)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon May 12 11:18:51 PDT 2025


================
@@ -40,3 +40,13 @@ struct S : public Base1<int>, public Base2<float> {
   // All initializers are correct, nothing to skip, diagnose 2 missing commas.
   S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}}
 };
+
+namespace GH113722 {
+struct S {
+  void m(int x = 0;   // expected-error {{unexpected end of default argument expression}} \
+                         expected-note {{to match this '('}}
+    #pragma unused(x) // expected-error {{expected ')'}} \
----------------
AaronBallman wrote:

> Does this mean we can't have pragmas in the middle of a statement?

Nope, this still works fine:
```
struct S {
  void m(int x =
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wconversion"
  1.2f
  #pragma clang diagnostic pop
  );
  void n(int x =
  1.2f
  );
};
```
I can add a test case for that if you want. This is just an issue with an ill-formed initializer, I believe.

https://github.com/llvm/llvm-project/pull/139595


More information about the cfe-commits mailing list