Va. Code Ann. § 64.2-731
A. Except as otherwise provided in subsection B, if a particular charitable purpose becomes unlawful, impracticable, impossible to achieve, or wasteful:
B. A provision in the terms of a charitable trust that would result in distribution of the trust property to a noncharitable beneficiary prevails over the power of the court under subsection A to apply cy pres to modify or terminate the trust only if, when the provision takes effect:
2005, c. 935, § 55-544.13; 2012, c. 614.