d: Enable private member access for __traits
[gcc.git] / gcc / d / dmd / traits.c
index 5fd4b486a9bd94483fc7e0ace9903b3b4dd7eaad..70f7f2cb582ec51a9e16b260fc3f534c7b66464e 100644 (file)
@@ -1103,12 +1103,14 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
             return new ErrorExp();
         }
 
+        // ignore symbol visibility and disable access checks for these traits
+        Scope *scx = sc->push();
+        scx->flags |= SCOPEignoresymbolvisibility | SCOPEnoaccesscheck;
+
         if (e->ident == Id::hasMember)
         {
             /* Take any errors as meaning it wasn't found
              */
-            Scope *scx = sc->push();
-            scx->flags |= SCOPEignoresymbolvisibility;
             ex = trySemantic(ex, scx);
             scx->pop();
             return ex ? True(e) : False(e);
@@ -1118,8 +1120,6 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
             if (ex->op == TOKdotid)
                 // Prevent semantic() from replacing Symbol with its initializer
                 ((DotIdExp *)ex)->wantsym = true;
-            Scope *scx = sc->push();
-            scx->flags |= SCOPEignoresymbolvisibility;
             ex = semantic(ex, scx);
             scx->pop();
             return ex;
@@ -1130,8 +1130,6 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
         {
             unsigned errors = global.errors;
             Expression *eorig = ex;
-            Scope *scx = sc->push();
-            scx->flags |= SCOPEignoresymbolvisibility;
             ex = semantic(ex, scx);
             if (errors < global.errors)
                 e->error("%s cannot be resolved", eorig->toChars());