Brian Foley 39879e4f40
[Sema] Note member decl when initializer list default constructs member (#121854)
Recently I had a scenario where I had:
1. A class C with many members m_1...m_n of the same type T
2. T's default constructor was deleted
3. I accidentally omitted an explicitly constructed member in the
initializer list C() : m_1(foo), m_2(bar), ... { }

Clang told me that T's default constructor was deleted, and told me that
the call to T() was in C() (which it implicitly was), but didn't tell me
which member was being default constructed.

It was difficult to fix this problem because I had no easy way to list
all the members of type T in C and C's superclasses which would have let
me find which member was missing,

clang/test/CXX/class/class.init/p1.cpp is a simplified version of this
problem (a2 is missing from the initializer list of B)
2025-02-03 19:57:37 +01:00

15 lines
396 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace test_deleted_ctor_note {
struct A {
int a;
A() = delete; // expected-note {{'A' has been explicitly marked deleted here}}
A(int a_) : a(a_) { }
};
struct B {
A a1, a2, a3; // expected-note {{default constructed field 'a2' declared here}}
B(int a_) : a1(a_), a3(a_) { } // expected-error{{call to deleted constructor of 'A'}}
};
}