diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-10-15 13:21:21 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-10-15 13:21:21 +0000 |
commit | a6e937ce32474934778346f4d51c3beec40e77ec (patch) | |
tree | 34b1e54fd8713891fbb7e5a6666f18a484c49be7 /lib/Sema/SemaDecl.cpp | |
parent | 2fb985bdda20037bda228628acd4cbaa8a3b36ac (diff) |
Diagnose C++ [class.mem]p13-14, where a class member has the same name
as the class itself. Fixes PR7082.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116573 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index bced4a0b8c..23721e5d99 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2300,7 +2300,24 @@ Decl *Sema::HandleDeclarator(Scope *S, Declarator &D, D.setInvalidType(); } } - + + // C++ [class.mem]p13: + // If T is the name of a class, then each of the following shall have a + // name different from T: + // - every static data member of class T; + // - every member function of class T + // - every member of class T that is itself a type; + if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) + if (Record->getIdentifier() && Record->getDeclName() == Name) { + Diag(D.getIdentifierLoc(), diag::err_member_name_of_class) + << Name; + + // If this is a typedef, we'll end up spewing multiple diagnostics. + // Just return early; it's safer. + if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) + return 0; + } + NamedDecl *New; TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S); @@ -7172,6 +7189,17 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, } } + // C++ [class.mem]p13: + // If T is the name of a class, then each of the following shall have a + // name different from T: + // - every enumerator of every member of class T that is an enumerated + // type + if (CXXRecordDecl *Record + = dyn_cast<CXXRecordDecl>( + TheEnumDecl->getDeclContext()->getRedeclContext())) + if (Record->getIdentifier() && Record->getIdentifier() == Id) + Diag(IdLoc, diag::err_member_name_of_class) << Id; + EnumConstantDecl *New = CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc, Id, Val); |