[clang] [clang] Mark constructors with invalid initializers as invalid (PR #137773)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 29 14:15:02 PDT 2025


================
@@ -2,16 +2,20 @@
 // RUN: %clang_cc1 -Wreorder -fsyntax-only -verify -std=c++98 %s
 // RUN: %clang_cc1 -Wreorder -fsyntax-only -verify -std=c++11 %s
 
-class A { 
+class A {
+  // expected-note at -1 {{candidate constructor}}
+#if __cplusplus >= 201103L // C++11 or later
+  // expected-note at -3 {{candidate constructor}}
+#endif
   int m;
 public:
    A() : A::m(17) { } // expected-error {{member initializer 'm' does not name a non-static data member or base class}}
-   A(int);
+   A(int); // expected-note {{candidate constructor}}
 };
 
 class B : public A { 
 public:
-  B() : A(), m(1), n(3.14) { }
+  B() : A(), m(1), n(3.14) { } // expected-error {{no matching constructor for initialization of 'A'}}
----------------
efriedma-quic wrote:

This doesn't seem like an improvement.  Is there some way we can recover more gracefully for constructors with a valid signature?

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


More information about the cfe-commits mailing list