Skip to content

Using the main function in a program is allowed #18915

@llvmbot

Description

@llvmbot
Bugzilla Link 18541
Resolution FIXED
Resolved on Jan 22, 2014 18:46
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor,@zygoloid

Extended Description

This causes an infinite loop:

int main() {auto* x = &main; x();}

[basic.start.main]/3 states:

"The function main shall not be used within a program."

I can even do things like

int x = 0; int main() {auto* f = &main; if (++x == 0) f();}

which run correctly.

gcc rejects taking the address of main.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions