[cfe-commits] r151005 - in /cfe/trunk: lib/Sema/SemaType.cpp test/CXX/basic/basic.types/p10.cpp
Eli Friedman
eli.friedman at gmail.com
Mon Feb 20 15:58:15 PST 2012
Author: efriedma
Date: Mon Feb 20 17:58:14 2012
New Revision: 151005
URL: http://llvm.org/viewvc/llvm-project?rev=151005&view=rev
Log:
Make RequireLiteralType work correctly with incomplete array types. PR12037.
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CXX/basic/basic.types/p10.cpp
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=151005&r1=151004&r2=151005&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Feb 20 17:58:14 2012
@@ -4249,7 +4249,9 @@
const PartialDiagnostic &PD) {
assert(!T->isDependentType() && "type should not be dependent");
- RequireCompleteType(Loc, T, 0);
+ QualType ElemType = Context.getBaseElementType(T);
+ RequireCompleteType(Loc, ElemType, 0);
+
if (T->isLiteralType())
return false;
@@ -4261,12 +4263,16 @@
if (T->isVariableArrayType())
return true;
- const RecordType *RT = T->getBaseElementTypeUnsafe()->getAs<RecordType>();
+ const RecordType *RT = ElemType->getAs<RecordType>();
if (!RT)
return true;
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+ // FIXME: Better diagnostic for incomplete class?
+ if (!RD->isCompleteDefinition())
+ return true;
+
// If the class has virtual base classes, then it's not an aggregate, and
// cannot have any constexpr constructors or a trivial default constructor,
// so is non-literal. This is better to diagnose than the resulting absence
Modified: cfe/trunk/test/CXX/basic/basic.types/p10.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.types/p10.cpp?rev=151005&r1=151004&r2=151005&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.types/p10.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.types/p10.cpp Mon Feb 20 17:58:14 2012
@@ -11,8 +11,25 @@
struct S { S(); };
constexpr int f2(S &) { return 0; }
+// FIXME: I'm not entirely sure whether the following is legal or not...
+struct BeingDefined;
+extern BeingDefined beingdefined;
+struct BeingDefined {
+ static constexpr BeingDefined& t = beingdefined;
+};
+
// - a class type that has all of the following properties:
+// (implied) - it is complete
+
+struct Incomplete;
+template<class T> struct ClassTemp {};
+
+constexpr Incomplete incomplete = {}; // expected-error {{constexpr variable cannot have non-literal type 'const Incomplete'}}
+constexpr Incomplete incomplete2[] = {}; // expected-error {{constexpr variable cannot have non-literal type 'Incomplete const[]'}}
+constexpr ClassTemp<int> classtemplate = {};
+constexpr ClassTemp<int> classtemplate2[] = {};
+
// - it has a trivial destructor
struct UserProvDtor {
constexpr int f(); // expected-error {{non-literal type 'UserProvDtor' cannot have constexpr members}}
More information about the cfe-commits
mailing list