Don't build a StringLiteral expression with reference type when

performing list-initialization of a char array reference from a braced
string literal of a smaller size.
This commit is contained in:
Richard Smith 2020-09-21 14:52:06 -07:00
parent 6a6b06f526
commit 0f6facca97
2 changed files with 11 additions and 1 deletions

View File

@ -8420,7 +8420,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
case SK_StringInit: {
QualType Ty = Step->Type;
CheckStringInit(CurInit.get(), ResultType ? *ResultType : Ty,
bool UpdateType = ResultType && Entity.getType()->isIncompleteArrayType();
CheckStringInit(CurInit.get(), UpdateType ? *ResultType : Ty,
S.Context.getAsArrayType(Ty), S);
break;
}

View File

@ -1,5 +1,14 @@
// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s
// This creates and lifetime-extends a 'const char[5]' temporary.
// CHECK: @_ZGR19extended_string_ref_ = internal constant [5 x i8] c"hi\00\00\00",
// CHECK: @extended_string_ref = constant [5 x i8]* @_ZGR19extended_string_ref_,
const char (&extended_string_ref)[5] = {"hi"};
// This binds directly to a string literal object.
// CHECK: @nonextended_string_ref = constant [3 x i8]* @.str
const char (&nonextended_string_ref)[3] = {"hi"};
namespace reference {
struct A {
int i1, i2;