data tree FEATURE do not add implicit nodes with false when
diff --git a/src/tree_data.c b/src/tree_data.c
index a95a8cb..f57c274 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1547,8 +1547,9 @@
 API LY_ERR
 lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff)
 {
-    struct lyd_node *node;
     LY_ERR ret = LY_SUCCESS;
+    struct lyd_node *node;
+    struct ly_set node_when = {0};
 
     LY_CHECK_ARG_RET(NULL, tree, LY_EINVAL);
     if (diff) {
@@ -1560,13 +1561,17 @@
         if (((node->flags & (LYD_DEFAULT | LYD_NEW)) != (LYD_DEFAULT | LYD_NEW)) &&
                 (node->schema->nodetype & LYD_NODE_INNER)) {
             LY_CHECK_GOTO(ret = lyd_new_implicit_r(node, lyd_node_children_p((struct lyd_node *)node), NULL, NULL, NULL,
-                    NULL, implicit_options, diff), cleanup);
+                    &node_when, implicit_options, diff), cleanup);
         }
 
         LYD_TREE_DFS_END(tree, node);
     }
 
+    /* resolve when and remove any invalid defaults */
+    LY_CHECK_GOTO(ret = lyd_validate_unres(&tree, &node_when, NULL, NULL, diff), cleanup);
+
 cleanup:
+    ly_set_erase(&node_when, NULL);
     if (ret && diff) {
         lyd_free_all(*diff);
         *diff = NULL;
@@ -1616,8 +1621,9 @@
 API LY_ERR
 lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options, struct lyd_node **diff)
 {
-    struct lyd_node *root, *d = NULL;
     LY_ERR ret = LY_SUCCESS;
+    struct lyd_node *root, *d = NULL;
+    struct ly_set node_when = {0};
 
     LY_CHECK_ARG_RET(NULL, tree, module, LY_EINVAL);
     if (diff) {
@@ -1625,7 +1631,10 @@
     }
 
     /* add all top-level defaults for this module */
-    LY_CHECK_GOTO(ret = lyd_new_implicit_r(NULL, tree, NULL, module, NULL, NULL, implicit_options, diff), cleanup);
+    LY_CHECK_GOTO(ret = lyd_new_implicit_r(NULL, tree, NULL, module, NULL, &node_when, implicit_options, diff), cleanup);
+
+    /* resolve when and remove any invalid defaults */
+    LY_CHECK_GOTO(ret = lyd_validate_unres(tree, &node_when, NULL, NULL, diff), cleanup);
 
     /* process nested nodes */
     LY_LIST_FOR(*tree, root) {
@@ -1643,6 +1652,7 @@
     }
 
 cleanup:
+    ly_set_erase(&node_when, NULL);
     if (ret && diff) {
         lyd_free_all(*diff);
         *diff = NULL;
diff --git a/src/tree_data.h b/src/tree_data.h
index a48814d..ee28c41 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1062,7 +1062,7 @@
 /** @} implicitoptions */
 
 /**
- * @brief Add any missing implicit nodes into a data subtree.
+ * @brief Add any missing implicit nodes into a data subtree. Default nodes with a false "when" are not added.
  *
  * @param[in] tree Tree to add implicit nodes into.
  * @param[in] implicit_options Options for implicit node creation, see @ref implicitoptions.
@@ -1072,7 +1072,7 @@
 LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff);
 
 /**
- * @brief Add any missing implicit nodes.
+ * @brief Add any missing implicit nodes. Default nodes with a false "when" are not added.
  *
  * @param[in,out] tree Tree to add implicit nodes into.
  * @param[in] ctx libyang context, must be set only if @p tree is an empty tree.
@@ -1083,7 +1083,7 @@
 LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options, struct lyd_node **diff);
 
 /**
- * @brief Add any missing implicit nodes of one module.
+ * @brief Add any missing implicit nodes of one module. Default nodes with a false "when" are not added.
  *
  * @param[in,out] tree Tree to add implicit nodes into.
  * @param[in] module Module whose implicit nodes to create.