aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-04-14 00:41:11 +0000
committerAnders Carlsson <andersca@mac.com>2011-04-14 00:41:11 +0000
commitb8fc45f8d0fdcc7908590115942d425bf4a924f1 (patch)
tree6fce29d2c5f4a58558dd13cd9ab306e9f84d17ea /lib/Sema/SemaInit.cpp
parent3e2193ce5feb2feb092e5ae615e85148e06e9fd2 (diff)
In C++, when initializing an array from a pascal string, it's OK if the array
is 1 element smaller than the string, because we can just strip off the last null character. This matches GCC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129490 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r--lib/Sema/SemaInit.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 1dff64e855..84ab23e584 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -96,6 +96,15 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
// the size may be smaller or larger than the string we are initializing.
// FIXME: Avoid truncation for 64-bit length strings.
if (S.getLangOptions().CPlusPlus) {
+ if (StringLiteral *SL = dyn_cast<StringLiteral>(Str)) {
+ // For Pascal strings it's OK to strip off the terminating null character,
+ // so the example below is valid:
+ //
+ // unsigned char a[2] = "\pa";
+ if (SL->isPascal())
+ StrLength--;
+ }
+
// [dcl.init.string]p2
if (StrLength > CAT->getSize().getZExtValue())
S.Diag(Str->getSourceRange().getBegin(),