[cfe-commits] r91792 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseDeclCXX.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp
John McCall
rjmccall at apple.com
Sat Dec 19 23:58:13 PST 2009
Author: rjmccall
Date: Sun Dec 20 01:58:13 2009
New Revision: 91792
URL: http://llvm.org/viewvc/llvm-project?rev=91792&view=rev
Log:
Don't inject the class name until that magical lbrace.
Because of the rules of base-class lookup* and the restrictions on typedefs, it
was actually impossible for this to cause any problems more serious than the
spurious acceptance of
template <class T> class A : B<A> { ... };
instead of
template <class T> class A : B<A<T> > { ... };
but I'm sure we can all agree that that is a very important restriction which
is well worth making another Parser->Sema call for.
(*) n.b. clang++ does not implement these rules correctly; we are not ignoring
non-type names
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=91792&r1=91791&r2=91792&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun Dec 20 01:58:13 2009
@@ -662,6 +662,12 @@
/// struct, or union).
virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl) { }
+ /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
+ /// C++ record definition's base-specifiers clause and are starting its
+ /// member declarations.
+ virtual void ActOnStartCXXMemberDeclarations(Scope *S, DeclPtrTy TagDecl,
+ SourceLocation LBraceLoc) { }
+
/// ActOnTagFinishDefinition - Invoked once we have finished parsing
/// the definition of a tag (enumeration, class, struct, or union).
virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl,
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=91792&r1=91791&r2=91792&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sun Dec 20 01:58:13 2009
@@ -1389,6 +1389,8 @@
return;
}
+ Actions.ActOnStartCXXMemberDeclarations(CurScope, TagDecl, LBraceLoc);
+
// C++ 11p3: Members of a class defined with the keyword class are private
// by default. Members of a class defined with the keywords struct or union
// are public by default.
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=91792&r1=91791&r2=91792&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Dec 20 01:58:13 2009
@@ -757,6 +757,12 @@
/// struct, or union).
virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl);
+ /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
+ /// C++ record definition's base-specifiers clause and are starting its
+ /// member declarations.
+ virtual void ActOnStartCXXMemberDeclarations(Scope *S, DeclPtrTy TagDecl,
+ SourceLocation LBraceLoc);
+
/// ActOnTagFinishDefinition - Invoked once we have finished parsing
/// the definition of a tag (enumeration, class, struct, or union).
virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=91792&r1=91791&r2=91792&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Dec 20 01:58:13 2009
@@ -4962,31 +4962,36 @@
// Enter the tag context.
PushDeclContext(S, Tag);
+}
- if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Tag)) {
- FieldCollector->StartClass();
+void Sema::ActOnStartCXXMemberDeclarations(Scope *S, DeclPtrTy TagD,
+ SourceLocation LBraceLoc) {
+ AdjustDeclIfTemplate(TagD);
+ CXXRecordDecl *Record = cast<CXXRecordDecl>(TagD.getAs<Decl>());
- if (Record->getIdentifier()) {
- // C++ [class]p2:
- // [...] The class-name is also inserted into the scope of the
- // class itself; this is known as the injected-class-name. For
- // purposes of access checking, the injected-class-name is treated
- // as if it were a public member name.
- CXXRecordDecl *InjectedClassName
- = CXXRecordDecl::Create(Context, Record->getTagKind(),
- CurContext, Record->getLocation(),
- Record->getIdentifier(),
- Record->getTagKeywordLoc(),
- Record);
- InjectedClassName->setImplicit();
- InjectedClassName->setAccess(AS_public);
- if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate())
- InjectedClassName->setDescribedClassTemplate(Template);
- PushOnScopeChains(InjectedClassName, S);
- assert(InjectedClassName->isInjectedClassName() &&
- "Broken injected-class-name");
- }
- }
+ FieldCollector->StartClass();
+
+ if (!Record->getIdentifier())
+ return;
+
+ // C++ [class]p2:
+ // [...] The class-name is also inserted into the scope of the
+ // class itself; this is known as the injected-class-name. For
+ // purposes of access checking, the injected-class-name is treated
+ // as if it were a public member name.
+ CXXRecordDecl *InjectedClassName
+ = CXXRecordDecl::Create(Context, Record->getTagKind(),
+ CurContext, Record->getLocation(),
+ Record->getIdentifier(),
+ Record->getTagKeywordLoc(),
+ Record);
+ InjectedClassName->setImplicit();
+ InjectedClassName->setAccess(AS_public);
+ if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate())
+ InjectedClassName->setDescribedClassTemplate(Template);
+ PushOnScopeChains(InjectedClassName, S);
+ assert(InjectedClassName->isInjectedClassName() &&
+ "Broken injected-class-name");
}
void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD,
Modified: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp?rev=91792&r1=91791&r2=91792&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp Sun Dec 20 01:58:13 2009
@@ -10,6 +10,7 @@
struct A::C : B { };
}
+// Test that successive base specifiers don't screw with each other.
namespace test1 {
struct Opaque1 {};
struct Opaque2 {};
@@ -27,3 +28,10 @@
C() : A(), test1::B(Opaque2()) {}
};
}
+
+// Test that we don't find the injected class name when parsing base
+// specifiers.
+namespace test2 {
+ template <class T> struct bar {}; // expected-note {{template parameter is declared here}}
+ template <class T> struct foo : bar<foo> {}; // expected-error {{template argument for template type parameter must be a type}}
+}
More information about the cfe-commits
mailing list