Carry-ons are measured at the airport before boarding the plane. It's done with metal measuring boxes just in the right size for the allowed carry-on dimensions. If your bag is too large and it isn't flexible, you won't be able to fit it inside. But airlines rarely ask you to use it.