From 0476d069e394fec587858985ddee870360aec1ee Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 13 Jun 2019 23:31:04 +0000 Subject: PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type nullptr_t does not access memory. We now reuse CK_NullToPointer to represent a conversion from a glvalue of type nullptr_t to a prvalue of nullptr_t where necessary. This reinstates r345562, reverted in r346065, now that CodeGen's handling of non-odr-used variables has been fixed. llvm-svn: 363337 --- clang/lib/Sema/SemaInit.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'clang/lib/Sema/SemaInit.cpp') diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 1a1d9347985..1301de4b111 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -7779,9 +7779,13 @@ ExprResult InitializationSequence::Perform(Sema &S, case SK_LValueToRValue: { assert(CurInit.get()->isGLValue() && "cannot load from a prvalue"); - CurInit = ImplicitCastExpr::Create(S.Context, Step->Type, - CK_LValueToRValue, CurInit.get(), - /*BasePath=*/nullptr, VK_RValue); + // C++ [conv.lval]p3: + // If T is cv std::nullptr_t, the result is a null pointer constant. + CastKind CK = + Step->Type->isNullPtrType() ? CK_NullToPointer : CK_LValueToRValue; + CurInit = + ImplicitCastExpr::Create(S.Context, Step->Type, CK, CurInit.get(), + /*BasePath=*/nullptr, VK_RValue); break; } -- cgit v1.2.3