Gus van Sant’s feel-good drama Finding Forrester, which arrives on Blu-ray and DVD this month, has been forgotten with good reason. It recycles from his earlier film Good Will Hunting the story of a wayward teenage genius nurtured by an older mentor, only this time the boy’s talents are literary, not mathematical. But it does have some curiosity value thanks to its title character.

The reclusive novelist William Forrester, played by Sean Connery, has a secret that is never mentioned on screen. I discovered it by accident when I met Van Sant in 2008 while he was editing Milk, his film about the openly gay politician Harvey Milk. It was odd, I suggested, that despite being out himself, Van Sant hadn’t made a picture with gay characters since My Own Private Idaho 15 years earlier. He looked mildly startled. “Wow … uh … I guess you’re right.” Then he put me straight: “Well, there was Finding Forrester.” I wracked my brains. Who was gay in that? “Sean,” he said, matter-of-factly. “It wasn’t in the script. The studio didn’t want us to advertise it. But Sean wanted to play that part as gay.”

Performers routinely give their characters histories to which audiences are oblivious. But this feels particularly intriguing in the case of Connery, who has never knowingly deviated on screen from staunch heterosexuality. Interviews he gave to promote the film don’t provide much clarity. “I suppose there could be undercurrents that my character is closeted,” he said. Either he is playing extremely hard-to-get, or his decision to make the character gay was so secret that even he forgot about it. There are clues in the film itself, which seems to present Forrester initially as a gay voyeur. When we first meet him, he is standing in his apartment, squinting through his binoculars. “What we have here is an adult male,” he purrs. “Quite pretty.” But the joke is on us: it’s only a Connecticut warbler. Forrester is a watcher of birds, not men.

When 16-year-old Jamal (Rob Brown) breaks into Forrester’s apartment as a dare, he accidentally leaves behind his rucksack, and the novelist later hangs the bag in his window as a taunt to the intruder. You might say it’s the first of their primitive courtship rituals. The youngster comes to retrieve his bag and finds the notebooks inside daubed with encouragements. Submitting an essay to Forrester, he places it tentatively on the writer’s doorstep like raw meat to coax a bear out of hiding.

If Connery really did play the part as secretly gay, he wouldn’t be the first actor to keep a character in the closet. Early in his career, Harrison Ford was the mildly sinister corporate PA in Francis Ford Coppola’s thriller The Conversation. “I played a character who was gay so nobody would recognise me from American Graffiti,” he said, referring to the George Lucas comedy in which he had appeared the previous year. “There was no role there until I decided to make him a homosexual.”

Whatever stories Ford told himself in order to bring the role to life were plainly successful. It’s a brief but effective performance, though one in which sexual orientation remains a private matter between actor and character. Unless, that is, you count the home-baked Christmas cookies he has brought into the office, which may be as much of a giveaway cliche as that incriminating bottle of Perrier in the black comedy Heathers.

Cary Grant and Martin Landau in North By Northwest. Photograph: MGM/REX/Shutterstock

Gay characters have always been siphoned off into the area of villainy, so it was nothing new for Ernest Lehman to write in his screenplay for North by Northwest that the menacing Leonard, played by Martin Landau, displays “unmistakably effeminate” behaviour. But it is Landau who now claims the credit for bringing layers of sexual jealousy to the role. “I decided to play him as a homosexual, very subtly, because otherwise he would have been just a henchman,” he told me. “He wasn’t a bad guy; he was just trying to keep a relationship alive by getting rid of the woman who had usurped him. I realised that all of this would make him very dangerous – it made his grievance personal. The only person who didn’t like this was James Mason because it cast aspersions on his character; it basically turned him into a bisexual.” Landau also claims that Lehman supplied an extra line (“Call it my woman’s intuition, if you will,” says Leonard at one point) to support his interpretation.

Arthur Laurents recalls prospective stars being scared off by the gay overtones in another Hitchcock thriller, Rope, which he co-wrote with Hume Cronyn. “We’d wanted Cary Grant for the teacher and Montgomery Clift for one of the boys, and they both turned it down for the same reason – their image. They felt they couldn’t risk it. Eventually John Dall and Farley Granger played the boys, and they were very aware of what they were doing. Jimmy Stewart, however, who played the teacher, wasn’t at all.”

Love interest … Charlton Heston in Ben-Hur Photograph: Allstar/Cinetext/MGM

Charlton Heston was just as oblivious to the subtext of Ben-Hur, which had been arrived at through the collusion of the writer Gore Vidal, the director William Wyler and Heston’s co-star, Stephen Boyd, who played Ben-Hur’s friend Messala. The two characters’ rivalry lacked weight so Vidal suggested that Messala hoped secretly to rekindle a boyhood romance between them. “Don’t tell Chuck,” said Wyler. However, Vidal did tip off Boyd. “He agreed to play the frustrated lover,” Vidal said. “Study his face in the reaction shots in that scene, and you will see that he plays it like a man starving.”

Adrien Brody, Woody Harrelson and Sean Penn in The Thin Red Line Photograph: Merie W Wallace/Associated Press

Actors are always developing interior lives for their characters: it’s what they do. The difference in the case of sexuality is that those choices are often regarded as commercially risky. After all, characters such as Corporal Fife (Adrien Brody) in The Thin Red Line and Paul Varjak (George Peppard) in Breakfast at Tiffany’s were straightened out en route from page to screen. A gay encounter in a prison shower in Midnight Express was altered on film to make it seem as though one man was rebuffing the other. “I wish that they’d let the steam in the shower come up and obscure the act itself instead of showing a rejection,” complained Billy Hayes, with some justification: he lived through the real-life version and knew what really happened.

‘All my characters are gay’ … Johnny Depp in Pirates of the Caribbean: Dead Man’s Chest. Photograph: Allstar/Disney/Sportsphoto Ltd.

When audiences at test screenings reacted negatively to two lesbian characters in the Steve Martin comedy LA Story, the studio responded by removing all references to their sexuality. So no wonder Disney executives were aghast when they clapped eyes on dailies showing Johnny Depp camping it up deliciously as Captain Jack Sparrow in Pirates of the Caribbean: The Curse of the Black Pearl. “They couldn’t stand him,” Depp said in 2010. “They just couldn’t stand him. I think it was Michael Eisner, the head of Disney at the time, who was quoted as saying, ‘He’s ruining the movie.’ Upper-echelon Disney-ites were going, ‘What’s wrong with him? Is he, you know, like some kind of weird simpleton? Is he drunk? By the way, is he gay?’ And so I actually told this woman who was the Disney-ite: ‘But didn’t you know that all my characters are gay?’ Which really made her nervous.”

Marlon Brando and Robert De Niro in The Score. Photograph: Reuters

In an ideal world, the subject of sexuality would be made visible without being promoted to the status of defining characteristic. For James Gandolfini in The Mexican and Laurie Metcalf in Internal Affairs, sexual preference is just one detail, alluded to in each case by a giveaway glance at someone of the same sex. The ageing criminal played by Marlon Brando in The Score was written as gay, although no explicit mention of it is made on screen. Sexuality asserts itself instead solely in the area of flamboyant costume design. Brando exhibits a fondness for silk ascots and kimonos. (No, not at the same time. He may be a crook but he’s no monster.) Critics got the hint well enough; Variety described the character as “an underworld Truman Capote.”

The gay viewer has traditionally been so severely starved of onscreen visibility that even slim pickings and burnt offerings can be rustled up into a banquet of sorts. A romance between a suicidal man and a corpse, which is what occurs in the recent Swiss Army Man, may not smack of positive representation but it is touchingly played by Paul Dano and Daniel Radcliffe with all the sincerity of Brokeback Mountain. (“We just kept rewriting and rewriting, until we allowed them to fall in love,” said the co-director Daniel Kwan.)

And is Casey Affleck really playing a closeted engineer in the Disney disaster movie The Finest Hours? He has no family to speak of and one colleague describes him as “a single man who’s always hiding down below”. Case closed, I’d say.

Finding Forrester is released on Blu-ray and DVD on 20 February