[cfe-commits] r82732 - in /cfe/trunk: include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Sema/Sema.h lib/Sema/SemaCXXScopeSpec.cpp test/SemaTemplate/explicit-specialization-member.cpp

Douglas Gregor dgregor at apple.com
Thu Sep 24 16:39:01 PDT 2009


Author: dgregor
Date: Thu Sep 24 18:39:01 2009
New Revision: 82732

URL: http://llvm.org/viewvc/llvm-project?rev=82732&view=rev
Log:
When entering the scope of a declarator, make sure that the scope is
complete (or, possibly causing template instantiation).

Test this via some explicit specializations of member functions.


Added:
    cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
Modified:
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=82732&r1=82731&r2=82732&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Sep 24 18:39:01 2009
@@ -300,7 +300,9 @@
   /// looked up in the declarator-id's scope, until the declarator is parsed and
   /// ActOnCXXExitDeclaratorScope is called.
   /// The 'SS' should be a non-empty valid CXXScopeSpec.
-  virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
+  /// \returns true if an error occurred, false otherwise.
+  virtual bool ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
+    return false;
   }
 
   /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=82732&r1=82731&r2=82732&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Sep 24 18:39:01 2009
@@ -1123,7 +1123,9 @@
     void EnterDeclaratorScope() {
       assert(!EnteredScope && "Already entered the scope!");
       assert(SS.isSet() && "C++ scope was not set!");
-      P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS);
+      if (P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS))
+        SS.setScopeRep(0);
+      
       if (!SS.isInvalid())
         EnteredScope = true;
     }

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=82732&r1=82731&r2=82732&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Sep 24 18:39:01 2009
@@ -2151,7 +2151,7 @@
   /// looked up in the declarator-id's scope, until the declarator is parsed and
   /// ActOnCXXExitDeclaratorScope is called.
   /// The 'SS' should be a non-empty valid CXXScopeSpec.
-  virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
+  virtual bool ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
 
   /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
   /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=82732&r1=82731&r2=82732&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Thu Sep 24 18:39:01 2009
@@ -519,10 +519,18 @@
 /// looked up in the declarator-id's scope, until the declarator is parsed and
 /// ActOnCXXExitDeclaratorScope is called.
 /// The 'SS' should be a non-empty valid CXXScopeSpec.
-void Sema::ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
+bool Sema::ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
   assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
-  if (DeclContext *DC = computeDeclContext(SS, true))
+  if (DeclContext *DC = computeDeclContext(SS, true)) {
+    // Before we enter a declarator's context, we need to make sure that
+    // it is a complete declaration context.
+    if (!DC->isDependentContext() && RequireCompleteDeclContext(SS))
+      return true;
+      
     EnterDeclaratorContext(S, DC);
+  }
+  
+  return false;
 }
 
 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously

Added: cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp?rev=82732&view=auto

==============================================================================
--- cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp (added)
+++ cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp Thu Sep 24 18:39:01 2009
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template<typename T>
+struct X0 {
+  typedef T* type;
+  
+  void f0(T);
+  void f1(type);
+};
+
+template<> void X0<char>::f0(char);
+template<> void X0<char>::f1(type);





More information about the cfe-commits mailing list