Index: clang/include/clang/Sema/Initialization.h =================================================================== --- clang/include/clang/Sema/Initialization.h +++ clang/include/clang/Sema/Initialization.h @@ -335,8 +335,13 @@ } /// Create the initialization entity for a temporary. - static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) { - return InitializeTemporary(TypeInfo, TypeInfo->getType()); + static InitializedEntity InitializeTemporary(ASTContext &Context, + TypeSourceInfo *TypeInfo) { + QualType Type = TypeInfo->getType(); + if (Context.getLangOpts().OpenCL && !Type.hasAddressSpace()) + Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private); + + return InitializeTemporary(TypeInfo, Type); } /// Create the initialization entity for a temporary. Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -1454,7 +1454,8 @@ "List initialization must have initializer list as expression."); SourceRange FullRange = SourceRange(TyBeginLoc, RParenOrBraceLoc); - InitializedEntity Entity = InitializedEntity::InitializeTemporary(TInfo); + InitializedEntity Entity = + InitializedEntity::InitializeTemporary(Context, TInfo); InitializationKind Kind = Exprs.size() ? ListInitialization @@ -5293,7 +5294,8 @@ S, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl()); - InitializedEntity To(InitializedEntity::InitializeTemporary(Args[0])); + InitializedEntity To( + InitializedEntity::InitializeTemporary(S.Context, Args[0])); InitializationKind InitKind(InitializationKind::CreateDirect(KWLoc, KWLoc, RParenLoc)); InitializationSequence Init(S, To, InitKind, ArgExprs); Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp =================================================================== --- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp +++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp @@ -32,6 +32,8 @@ __local X lx; __private X x; + __private X tx = X(); + __private Y py; __constant Y cy1; // expected-error{{variable in constant address space must be initialized}} __constant Y cy2(1); // expected-error{{no matching constructor for initialization of '__constant Y'}} Index: clang/test/SemaOpenCLCXX/temporaries.clcpp =================================================================== --- /dev/null +++ clang/test/SemaOpenCLCXX/temporaries.clcpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 %s -pedantic -ast-dump | FileCheck %s + +struct X { + X() __private = default; +}; + +// CHECK: VarDecl {{.*}} gx +// CHECK: CXXTemporaryObjectExpr {{.*}} '__private X' +__global X gx = X(); + +void k() { + // CHECK: VarDecl {{.*}} x1 + // CHECK: CXXTemporaryObjectExpr {{.*}} '__private X' + X x1 = X(); + + // CHECK: VarDecl {{.*}} x2 + // CHECK: CXXConstructExpr {{.*}} 'const __private X' + const X x2; +}