Skip to content

Commit ebbb544

Browse files
royjacobsontru
authored andcommitted
[Clang] Fix variant crashes from GH58028, GH57370
Fixes a null dereference in some diagnostic issuing code. Closes #57370 Closes #58028 Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D134885 (cherry picked from commit 9415aad)
1 parent 77ff99c commit ebbb544

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,10 @@ void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
695695
// member of reference type uninitialized, the program is
696696
// ill-formed.
697697
SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
698-
<< Field->getType()
699-
<< ILE->getSyntacticForm()->getSourceRange();
700-
SemaRef.Diag(Field->getLocation(),
701-
diag::note_uninit_reference_member);
698+
<< Field->getType()
699+
<< (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm())
700+
->getSourceRange();
701+
SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member);
702702
}
703703
hadError = true;
704704
return;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang_cc1 -fsyntax-only %s --std=c++17 -verify
2+
// This is a reduction of GH57370 and GH58028, originally appearing
3+
// in libstdc++'s variant code.
4+
5+
struct V1 {};
6+
struct V2 : V1 {
7+
int &a;
8+
};
9+
10+
template <class T> using void_t = void;
11+
12+
template <class T> struct X { T x; };
13+
14+
template <class T1, class T2, class = void> struct Variant {
15+
Variant() = delete; // expected-note {{deleted here}}
16+
};
17+
18+
template <class T1, class T2>
19+
struct Variant<T1, T2, void_t<decltype(X<T2>{T1()})>> {};
20+
21+
void f() {
22+
Variant<V1, V1>();
23+
Variant<V1, V2>(); // expected-error {{call to deleted constructor}}
24+
}

0 commit comments

Comments
 (0)