In its first decision, U.S. - Gasoline, the Appellate Body famously (relatively speaking) said:
One problem with the [panel's] reasoning ... is that the Panel asked itself whether the "less favourable treatment" of imported gasoline was "primarily aimed at" the conservation of natural resources, rather than whether the "measure", i.e. the baseline establishment rules, were "primarily aimed at" conservation of clean air. In our view, the Panel here was in error in referring to its legal conclusion on Article III:4 instead of the measure in issue. The result of this analysis is to turn Article XX on its head. Obviously, there had to be a finding that the measure provided "less favourable treatment" under Article III:4 before the Panel examined the "General Exceptions" contained in Article XX. That, however, is a conclusion of law. The chapeau of Article XX makes it clear that it is the "measures" which are to be examined under Article XX(g), and not the legal finding of "less favourable treatment."
Thus, according to the AB, it's the measure as a whole that must be examined for the "relating to" aspect of Article XX(g). Applying this standard, the AB held:
The baseline establishment rules, taken as a whole (that is, the provisions relating to establishment of baselines for domestic refiners, along with the provisions relating to baselines for blenders and importers of gasoline), need to be related to the "non-degradation" requirements set out elsewhere in the Gasoline Rule. Those provisions can scarcely be understood if scrutinized strictly by themselves, totally divorced from other sections of the Gasoline Rule which certainly constitute part of the context of these provisions. The baseline establishment rules whether individual or statutory, were designed to permit scrutiny and monitoring of the level of compliance of refiners, importers and blenders with the "non-degradation" requirements. Without baselines of some kind, such scrutiny would not be possible and the Gasoline Rule's objective of stabilizing and preventing further deterioration of the level of air pollution prevailing in 1990, would be substantially frustrated. The relationship between the baseline establishment rules and the "non-degradation" requirements of the Gasoline Rule is not negated by the inconsistency, found by the Panel, of the baseline establishment rules with the terms of Article III:4. We consider that, given that substantial relationship, the baseline establishment rules cannot be regarded as merely incidentally or inadvertently aimed at the conservation of clean air in the United States for the purposes of Article XX(g).
But reading the old GATT U.S. - Section 337 case recently, I came across the very different approach taken by the panel there in the context of "necessity" under Article XX(d), along with what I thought was a pretty good rationale:
5.27 Bearing in mind the foregoing and that it is up to the contracting party seeking to justify measures under Article XX(d) to demonstrate that those measures are "necessary" within the meaning of that provision, the Panel considered whether the inconsistencies that it had found with Article III:4 can be justified as "necessary" in terms of Article XX(d). The Panel first examined the argument of the United States that the Panel should consider not whether the individual elements of Section 337 are "necessary" but rather whether Section 337 as a system is "necessary" for the enforcement of United States patent laws (paragraphs 3.57-3.58). The Panel did not accept this contention since it would permit contracting parties to introduce GATT inconsistencies that are not necessary simply by making them part of a scheme which contained elements that are necessary. In the view of the Panel, what has to be justified as "necessary" under Article XX(d) is each of the inconsistencies with another GATT Article found to exist, i.e. in this case, whether the differences between Section 337 and federal district court procedures that result in less favourable treatment of imported products within the meaning of Article III:4, as outlined above (paragraph 5.20), are necessary.
So, the Panel said it would consider whether "the inconsistencies that it had found" could be justified as "necessary." In doing so, the Panel rejected the U.S. argument for examining "Section 337 as a whole," on the basis that this approach "would permit contracting parties to introduce GATT inconsistencies that are not necessary simply by making them part of a scheme which contained elements that are necessary." This seems fairly convincing to me. In essence, if panels look at the measure as a whole, Members can bury any sort of violation they want as part of a broader measure and they will still be able to get past the "necessary" / "relating to" prong. Of course, they still have to satisfy the chapeau, but nevertheless doesn't this approach make it easier to slip through discrimination and other trade barriers as part of non-trade policies?