The US Supreme Court has agreed to decide the constitutionality of a law that allows the federal government to indefinitely detain a person deemed "sexually dangerous," even after that person has finished serving a full prison sentence.

The issue arises in the case of a man who has been confined to a North Carolina federal prison for more than two years after completing his three-year sentence for receiving child pornography. The man, Graydon Earl Comstock, has no firm release date.

In January, a federal appeals court panel declared the law unconstitutional. "The Constitution does not empower the federal government to confine a person solely because of asserted 'sexual dangerousness' when the government need not allege (let alone prove) that this 'dangerousness' violates any federal law," wrote Judge Diana Gribbon Motz of the Fourth Circuit Court of Appeals based in Richmond.

The provision in question was passed as part of the Adam Walsh Child Protection and Safety Act of 2006. It authorizes the attorney general to seek the court-ordered, open-ended civil commitment of any "sexually dangerous person" already in US custody.

The measure is controversial in part because it relies on anticipation of future dangerousness to society, rather than actual or planned violations of law.

The case, which the high court will hear in the fall, is significant legally because it tests the breadth of federal power under the Constitution's necessary and proper clause. The Obama administration is currently considering enacting a legal regime to indefinitely detain Al Qaeda terror suspects currently at Guantánamo who can't be put on trial but who are deemed too dangerous to be released.