Hyphens almost always resolve the ambiguity.

But that would be wrong. Ancient History, the noun and discipline, is not hyphenated, not even when it qualifies another noun. You might argue that you should use a comma in the less flattering case: the ancient, history teacher. And you could always arrange the constituent words differently, e.g., the rubber bumpers on that baby buggy, but that ruins the effect. And besides, when speaking nobody can hear your hyphens. You could use pauses. Less commas than ellipses. But seriously, ambiguity of this kind runs rampant throughout language. If it's not obvious from the context, restatement and rearrangement usually fix things.