diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-05-14 20:15:04 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-05-14 20:15:04 +0000 |
commit | d699da427a4c49bc01c9ee3d031c7885383568f9 (patch) | |
tree | 01cd593aac8dad7f8b5760864ce5737ef39f7638 /clang/lib/Sema/SemaDecl.cpp | |
parent | 771f2422d06b1aca660333ff89ef62529e395f27 (diff) | |
download | bcm5719-llvm-d699da427a4c49bc01c9ee3d031c7885383568f9.tar.gz bcm5719-llvm-d699da427a4c49bc01c9ee3d031c7885383568f9.zip |
PR37450: Fix bug that disabled some type checks for variables with deduced types.
Also improve diagnostic for the case where a type is non-literal because it's a lambda.
llvm-svn: 332286
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 377bb106325..9a1ab4a3c58 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7293,8 +7293,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { if (NewVD->isInvalidDecl()) return; - TypeSourceInfo *TInfo = NewVD->getTypeSourceInfo(); - QualType T = TInfo->getType(); + QualType T = NewVD->getType(); // Defer checking an 'auto' type until its initializer is attached. if (T->isUndeducedType()) @@ -7438,10 +7437,18 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { bool SizeIsNegative; llvm::APSInt Oversized; - TypeSourceInfo *FixedTInfo = - TryToFixInvalidVariablyModifiedTypeSourceInfo(TInfo, Context, - SizeIsNegative, Oversized); - if (!FixedTInfo && T->isVariableArrayType()) { + TypeSourceInfo *FixedTInfo = TryToFixInvalidVariablyModifiedTypeSourceInfo( + NewVD->getTypeSourceInfo(), Context, SizeIsNegative, Oversized); + QualType FixedT; + if (FixedTInfo && T == NewVD->getTypeSourceInfo()->getType()) + FixedT = FixedTInfo->getType(); + else if (FixedTInfo) { + // Type and type-as-written are canonically different. We need to fix up + // both types separately. + FixedT = TryToFixInvalidVariablyModifiedType(T, Context, SizeIsNegative, + Oversized); + } + if ((!FixedTInfo || FixedT.isNull()) && T->isVariableArrayType()) { const VariableArrayType *VAT = Context.getAsVariableArrayType(T); // FIXME: This won't give the correct result for // int a[10][n]; @@ -7470,7 +7477,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { } Diag(NewVD->getLocation(), diag::warn_illegal_constant_array_size); - NewVD->setType(FixedTInfo->getType()); + NewVD->setType(FixedT); NewVD->setTypeSourceInfo(FixedTInfo); } |