A class of convex noncoercive functionals and masonry-like materials