diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4970,6 +4970,9 @@ SourceLocation getBeginLoc() const LLVM_READONLY; SourceLocation getEndLoc() const LLVM_READONLY; + SourceRange getSourceRange() const LLVM_READONLY { + return SourceRange(getBeginLoc(), getEndLoc()); + } static bool classof(const Stmt *T) { return T->getStmtClass() == InitListExprClass; diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -695,8 +695,7 @@ // member of reference type uninitialized, the program is // ill-formed. SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized) - << Field->getType() - << ILE->getSyntacticForm()->getSourceRange(); + << Field->getType() << ILE->getSourceRange(); SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member); } diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp --- a/clang/test/SemaCXX/uninitialized.cpp +++ b/clang/test/SemaCXX/uninitialized.cpp @@ -1472,3 +1472,20 @@ }; }; Outer::Inner outerinner; + +namespace crash_on_report_uninitialized_field { +struct S { + union { + struct { + const int &f0; + const float &f1; // expected-note{{uninitialized reference member is here}} + }; + double d; + }; +}; +void bar(struct S &s); +void foo(int i, float f) { + S s = {.f0 = i}; // expected-error{{reference member of type 'const float &' uninitialized}} + bar(s); +} +} // namespace crash_on_report_uninitialized_field