aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-03 17:18:57 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-03 17:18:57 +0000
commited4ec8f6d183c247a4528ff846669b02f2326185 (patch)
treebb731ad8a547ba30f08537851f7ee49b930eed8f /lib/Sema
parent578aa64fd162e9b728424e54c5a0a7ec53e7b65a (diff)
One can use "class" and "struct" interchangeably to refer to a class
in C++. Fixes <rdar://problem/6815995>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70784 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/Sema.h27
-rw-r--r--lib/Sema/SemaDecl.cpp2
-rw-r--r--lib/Sema/SemaTemplate.cpp6
3 files changed, 32 insertions, 3 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index e222c9aa3c..2bfc6b7857 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -429,6 +429,33 @@ public:
virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
RecordDecl *Record);
+ /// \brief Determine whether a tag with a given kind is acceptable
+ /// for a redeclaration of a tag type declared with another tag.
+ ///
+ /// \p T1 and \p T2 are the tag kinds. Since the rules for
+ /// redeclaration of tags are symmetric, it does not matter which is
+ /// the previous declaration and which is the new declaration.
+ bool isAcceptableTagRedeclaration(TagDecl::TagKind T1, TagDecl::TagKind T2) {
+ // C++ [dcl.type.elab]p3:
+ // The class-key ore num keyword present in the
+ // elaborated-type-specifier shall agree in kind with the
+ // declaration to which the name in theelaborated-type-specifier
+ // refers. This rule also applies to the form of
+ // elaborated-type-specifier that declares a class-name or
+ // friend class since it can be construed as referring to the
+ // definition of the class. Thus, in any
+ // elaborated-type-specifier, the enum keyword shall be used to
+ // refer to an enumeration (7.2), the union class-keyshall be
+ // used to refer to a union (clause 9), and either the class or
+ // struct class-key shall be used to refer to a class (clause 9)
+ // declared using the class or struct class-key.
+ if (T1 == T2)
+ return true;
+
+ return (T1 == TagDecl::TK_struct || T1 == TagDecl::TK_class) &&
+ (T2 == TagDecl::TK_struct || T2 == TagDecl::TK_class);
+ }
+
virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
SourceLocation KWLoc, const CXXScopeSpec &SS,
IdentifierInfo *Name, SourceLocation NameLoc,
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 9647740b14..69989b131d 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3295,7 +3295,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
if (TK == TK_Reference || isDeclInScope(PrevDecl, SearchDC, S)) {
// Make sure that this wasn't declared as an enum and now used as a
// struct or something similar.
- if (PrevTagDecl->getTagKind() != Kind) {
+ if (!isAcceptableTagRedeclaration(PrevTagDecl->getTagKind(), Kind)) {
bool SafeToContinue
= (PrevTagDecl->getTagKind() != TagDecl::TK_enum &&
Kind != TagDecl::TK_enum);
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 43713e11f1..3649abd9a7 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -461,7 +461,7 @@ Sema::ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
// the class-key shall agree in kind with the original class
// template declaration (7.1.5.3).
RecordDecl *PrevRecordDecl = PrevClassTemplate->getTemplatedDecl();
- if (PrevRecordDecl->getTagKind() != Kind) {
+ if (!isAcceptableTagRedeclaration(PrevRecordDecl->getTagKind(), Kind)) {
Diag(KWLoc, diag::err_use_with_wrong_tag)
<< Name
<< CodeModificationHint::CreateReplacement(KWLoc,
@@ -1975,7 +1975,9 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
case DeclSpec::TST_union: Kind = TagDecl::TK_union; break;
case DeclSpec::TST_class: Kind = TagDecl::TK_class; break;
}
- if (ClassTemplate->getTemplatedDecl()->getTagKind() != Kind) {
+ if (!isAcceptableTagRedeclaration(
+ ClassTemplate->getTemplatedDecl()->getTagKind(),
+ Kind)) {
Diag(KWLoc, diag::err_use_with_wrong_tag)
<< ClassTemplate
<< CodeModificationHint::CreateReplacement(KWLoc,