In case A attacks B with a ranged attack, does B get cover?
I ask because it seems to me that he might not. In the image above I assumed that A has chosen the upper right corner of his square as being the most favorable for his ranged attack.
To determine whether your target has cover from your ranged attack, choose a corner of your square. If any line from this corner to any corner of the target’s square passes through a square or border that blocks line of effect or provides cover, or through a square occupied by a creature, the target has cover (+4 to AC). (PHB p. 150)
The question is whether the line that runs left along the wall provides cover.
But A surely has cover from B's melee attacks.
When making a melee attack against an adjacent target, your target has cover if any line from your square to the target’s square goes through a wall (including a low wall). (PHB p.151)
If you draw lines from the bottom left corner of B's square you certainly cross the walls, so A definetively has cover from B's melee attack.
That would mean that a ranged attacker (A) standing right around the corner of a melee attacker (B) can shoot the melee attacker without penalty and without risking attacks of opportunity. That does not feel right.
On the other hand - if a line running along a wall grants cover you could not shoot down a straight hallway without cover. (See image below) That does not feel right either.