summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/Sema.h2
-rw-r--r--clang/lib/Sema/SemaCXXScopeSpec.cpp30
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
-rw-r--r--clang/lib/Sema/SemaExpr.cpp2
-rw-r--r--clang/lib/Sema/SemaLookup.cpp2
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp35
6 files changed, 70 insertions, 3 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index b3669bc74d2..2e02004113f 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -1394,6 +1394,8 @@ public:
TypeTy *Ty,
SourceLocation RParen);
+ bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
+
/// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
/// global scope ('::').
virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index c8a86cfd7d1..7773d288ae5 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -17,6 +17,36 @@
#include "llvm/ADT/STLExtras.h"
using namespace clang;
+/// \brief Require that the context specified by SS be complete.
+///
+/// If SS refers to a type, this routine checks whether the type is
+/// complete enough (or can be made complete enough) for name lookup
+/// into the DeclContext. A type that is not yet completed can be
+/// considered "complete enough" if it is a class/struct/union/enum
+/// that is currently being defined. Or, if we have a type that names
+/// a class template specialization that is not a complete type, we
+/// will attempt to instantiate that class template.
+bool Sema::RequireCompleteDeclContext(const CXXScopeSpec &SS) {
+ if (!SS.isSet() || SS.isInvalid())
+ return false;
+
+ DeclContext *DC = static_cast<DeclContext *>(SS.getScopeRep());
+ if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
+ // If we're currently defining this type, then lookup into the
+ // type is okay: don't complain that it isn't complete yet.
+ const TagType *TagT = Context.getTypeDeclType(Tag)->getAsTagType();
+ if (TagT->isBeingDefined())
+ return false;
+
+ // The type must be complete.
+ return RequireCompleteType(SS.getRange().getBegin(),
+ Context.getTypeDeclType(Tag),
+ diag::err_incomplete_nested_name_spec,
+ SS.getRange());
+ }
+
+ return false;
+}
/// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
/// global scope ('::').
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 35573bb33d8..03d00b83a3c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1255,6 +1255,7 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl,
D.getIdentifierLoc());
} else { // Something like "int foo::x;"
DC = static_cast<DeclContext*>(D.getCXXScopeSpec().getScopeRep());
+ // FIXME: RequireCompleteDeclContext(D.getCXXScopeSpec()); ?
PrevDecl = LookupQualifiedName(DC, Name, LookupOrdinaryName, true);
// C++ 7.3.1.2p2:
@@ -2895,6 +2896,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
goto CreateNewDecl;
}
+ // FIXME: RequireCompleteDeclContext(SS)?
DC = static_cast<DeclContext*>(SS.getScopeRep());
SearchDC = DC;
// Look-up name inside 'foo::'.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9a86d65f9a0..95c0baae569 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4344,6 +4344,8 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
if (!Dependent && !ArgTy->isRecordType())
return Diag(TypeLoc, diag::err_offsetof_record_type) << ArgTy;
+ // FIXME: Does the type need to be complete?
+
// Otherwise, create a null pointer as the base, and iteratively process
// the offsetof designators.
QualType ArgTyPtr = Context.getPointerType(ArgTy);
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index dd9c850d089..a93689c9a05 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1035,7 +1035,7 @@ Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS,
bool RedeclarationOnly, bool AllowBuiltinCreation,
SourceLocation Loc) {
if (SS) {
- if (SS->isInvalid())
+ if (SS->isInvalid() || RequireCompleteDeclContext(*SS))
return LookupResult::CreateLookupResult(Context, 0);
if (SS->isSet())
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 21694b2e739..d630e801b02 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -655,13 +655,44 @@ Sema::InstantiateClassTemplateSpecialization(
// Start the definition of this instantiation.
ClassTemplateSpec->startDefinition();
- // FIXME: Create the injected-class-name for the
- // instantiation. Should this be a typedef or something like it?
// Instantiate the base class specifiers.
if (InstantiateBaseSpecifiers(ClassTemplateSpec, Template))
Invalid = true;
+ // FIXME: Create the injected-class-name for the
+ // instantiation. Should this be a typedef or something like it?
+
+ RecordDecl *Pattern = Template->getTemplatedDecl();
+
+ for (RecordDecl::decl_iterator Member = Pattern->decls_begin(),
+ MemberEnd = Pattern->decls_end();
+ Member != MemberEnd; ++Member) {
+ if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(*Member)) {
+ // FIXME: Simplified instantiation of typedefs needs to be made
+ // "real".
+ QualType T = Typedef->getUnderlyingType();
+ if (T->isDependentType()) {
+ T = InstantiateType(T, ClassTemplateSpec->getTemplateArgs(),
+ ClassTemplateSpec->getNumTemplateArgs(),
+ Typedef->getLocation(),
+ Typedef->getDeclName());
+ if (T.isNull()) {
+ Invalid = true;
+ T = Context.IntTy;
+ }
+ }
+
+ // Create the new typedef
+ TypedefDecl *New
+ = TypedefDecl::Create(Context, ClassTemplateSpec,
+ Typedef->getLocation(),
+ Typedef->getIdentifier(),
+ T);
+ ClassTemplateSpec->addDecl(New);
+ }
+ }
+
// FIXME: Instantiate all of the members.
// Add any implicitly-declared members that we might need.
OpenPOWER on IntegriCloud