How can I make a tool drop blocks with CanPlaceOn tag

In Adventure mode, I'm trying to let a player get blocks that he can place later, is there a way to do it directly or do I have to change them in his inventory?
Situation: The player gets a tool that will allow him to clear a boulder blocking the road. Further down the path, he encounters a broken bridge, and I want him to use the blocks he gathered before to rebuild it.
At the moment, if I build the boulder with blocks having the CanPlaceOn
tag, the tag disappear when the player destroys them and they go in its inventory.
Best Answer
Use a /fill clock hooked up to three command blocks to add the tag to item entities. Unfortunately, I don't know if it's possible to limit this to only those created with a specific tool.
First, create a scoreboard objective to keep track of the items you'll be adding the tag to.
/scoreboard objectives add itemID dummy
The first command block (order of execution does matter) in the fill clock will reset the objective for all item entities currently loaded.
/scoreboard players set @e[type=Item] itemID 0
The second sets the score based upon item id. Note that you can affect different types of items by assigning different values.
/scoreboard players set @e[type=Item] itemID 1 {Item:{id:minecraft:stone}}
Lastly, add the CanPlaceOn tag to all items with the right score.
/entitydata @e[score_itemID_min=1,score_itemID=1] {Item:{tag:{CanPlaceOn:["minecraft:stone"]}}}
Pictures about "How can I make a tool drop blocks with CanPlaceOn tag"



How to use Can_Break and Can_Place Minecraft bedrock and EDU Tags
More answers regarding how can I make a tool drop blocks with CanPlaceOn tag
Answer 2
As of Minecraft 1.13, this can be done in just one command (not counting set-up):
Set-up:
/scoreboard objectives add life minecraft.custom:minecraft.timeSinceDeath
Every tick:
/execute as @a[nbt={SelectedItem:<tool>}] as @e[type=item,distance=..5,nbt={Item:<Data Tags of Item>}] run data merge entity @s {Item:{tag:{CanPlaceOn:["<Block That Can Be Placed On>"]}}}
This is derived from ModDL's answer, however the conversion to 1.13 was sufficiently different that I felt it merited an answer instead of a comment.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Jill Burrow, Monstera, Anna Shvets, Klaus Nielsen