[cfe-commits] r141543 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp
Douglas Gregor
dgregor at apple.com
Mon Oct 10 09:05:18 PDT 2011
Author: dgregor
Date: Mon Oct 10 11:05:18 2011
New Revision: 141543
URL: http://llvm.org/viewvc/llvm-project?rev=141543&view=rev
Log:
When adding a direct initializer to a declaration, allow the
initializer to update the type of the declaration. For example, this
allows us to determine the size of an incomplete array from its
initializer. Fixes PR10288.
Added:
cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=141543&r1=141542&r2=141543&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Oct 10 11:05:18 2011
@@ -9088,6 +9088,7 @@
// class type.
if (!VDecl->getType()->isDependentType() &&
+ !VDecl->getType()->isIncompleteArrayType() &&
RequireCompleteType(VDecl->getLocation(), VDecl->getType(),
diag::err_typecheck_decl_incomplete_type)) {
VDecl->setInvalidDecl();
@@ -9163,14 +9164,19 @@
= InitializationKind::CreateDirect(VDecl->getLocation(),
LParenLoc, RParenLoc);
+ QualType T = VDecl->getType();
InitializationSequence InitSeq(*this, Entity, Kind,
Exprs.get(), Exprs.size());
- ExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs));
+ ExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs), &T);
if (Result.isInvalid()) {
VDecl->setInvalidDecl();
return;
+ } else if (T != VDecl->getType()) {
+ VDecl->setType(T);
+ Result.get()->setType(T);
}
+
Expr *Init = Result.get();
CheckImplicitConversions(Init, LParenLoc);
Added: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp?rev=141543&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp (added)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp Mon Oct 10 11:05:18 2011
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+char x1[]("hello");
+extern char x1[6];
+
+char x2[] = "hello";
+extern char x2[6];
Propchange: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list