Disgraced r&b singer R. Kelly has allegedly been having sex with underage girls for decades and also allegedly been giving them herpes -- but his attorney has slammed a state law prohibiting people with sexually-transmitted diseases from having intercourse.

According to Steven Greenberg, the law is "unconstitutional."

Per New York, it is a criminal offense for someone who knows they have an "infectious venereal disease" to sleep with another person.

Kelly has always maintained that he does not have genital herpes, but according to court docs, the star's medical records show that he had an "infectious venereal disease' at the time that he allegedly slept with Faith Rodgers -- one of his alleged victims.

"This statute is facially unconstitutional. It prohibits sexual intercourse by anybody who has an STD. The definition is vast, ranging from HIV to yeast infections … It includes HPV and' scabbies,'" Greenberg wrote.

"The only requirement is that the individual knows that they have the venereal disease. In other words, it prohibits two consenting adults from having sexual intercourse if either, or both, know that they have an infectious venereal disease," he continued.

"It does not require that the disease be passed on, nor does it allow the consenting adults to have sexual intercourse if the venereal disease is disclosed beforehand. It does not permit the use of a condom, or account for modern day suppression drugs."