};
-class TypedefDecl : public TypeDecl {
+class TypedefDecl : public TypeDecl, public Redeclarable<TypedefDecl> {
/// UnderlyingType - This is the type the typedef is set to.
TypeSourceInfo *TInfo;
IdentifierInfo *Id, TypeSourceInfo *TInfo)
: TypeDecl(Typedef, DC, L, Id), TInfo(TInfo) {}
- virtual ~TypedefDecl() {}
+ virtual ~TypedefDecl();
public:
static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
return TInfo;
}
+ /// Retrieves the canonical declaration of this typedef.
+ TypedefDecl *getCanonicalDecl() {
+ return getFirstDeclaration();
+ }
+ const TypedefDecl *getCanonicalDecl() const {
+ return getFirstDeclaration();
+ }
+
QualType getUnderlyingType() const {
return TInfo->getType();
}
return new (C) TypedefDecl(DC, L, Id, TInfo);
}
+// Anchor TypedefDecl's vtable here.
+TypedefDecl::~TypedefDecl() {}
+
EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, SourceLocation TKL,
EnumDecl *PrevDecl) {
}
// Verify the old decl was also a type.
- TypeDecl *Old = 0;
- if (!OldDecls.isSingleResult() ||
- !(Old = dyn_cast<TypeDecl>(OldDecls.getFoundDecl()))) {
+ TypeDecl *Old = OldDecls.getAsSingle<TypeDecl>();
+ if (!Old) {
Diag(New->getLocation(), diag::err_redefinition_different_kind)
<< New->getDeclName();
return New->setInvalidDecl();
}
+ // The types match. Link up the redeclaration chain if the old
+ // declaration was a typedef.
+ // FIXME: this is a potential source of wierdness if the type
+ // spellings don't match exactly.
+ if (isa<TypedefDecl>(Old))
+ New->setPreviousDeclaration(cast<TypedefDecl>(Old));
+
if (getLangOptions().Microsoft)
return;
if (Invalid)
Typedef->setInvalidDecl();
+ if (TypedefDecl *Prev = D->getPreviousDeclaration()) {
+ NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(Prev, TemplateArgs);
+ Typedef->setPreviousDeclaration(cast<TypedefDecl>(InstPrev));
+ }
+
Owner->addDecl(Typedef);
return Typedef;
struct s { };
+// PR5874
+namespace test1 {
+ typedef int foo;
+ namespace a { using test1::foo; };
+ typedef int foo;
+ using namespace a;
+ foo x;
+}