diff --git a/src/scanner.l b/src/scanner.l
index 15e5f86..f28a2a1 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -6276,6 +6276,8 @@ static void parseCompounds(Entry *rt)
       initEntry();
       gstat = FALSE;
       int ni=ce->name.findRev("::"); if (ni==-1) ni=0; else ni+=2;
+      bool popAnonNamespace = FALSE;
+      bool oldIsStatic = gstat;
       // set default protection based on the compound type
       if( ce->section==Entry::CLASS_SEC ) // class
       {
@@ -6313,6 +6315,7 @@ static void parseCompounds(Entry *rt)
 	if (ce->section == Entry::NAMESPACE_SEC ) // unnamed namespace
 	{
           current->stat = gstat = TRUE;
+          popAnonNamespace = TRUE;
 	}
 	current->protection = protection = ce->protection;
       }
@@ -6334,6 +6337,12 @@ static void parseCompounds(Entry *rt)
       //forceEndGroup();
 
       groupLeaveCompound(yyFileName,yyLineNr,ce->name);
+
+      if (popAnonNamespace)
+      {
+        //dbg(("scan: pc: popping anon namespace\n"));
+        gstat = oldIsStatic;
+      }
       
       delete current; current=0;
       ce->program.resize(0);
