[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 01:28:00 PDT 2024


https://github.com/MitalAshok requested changes to this pull request.

You can put some of the tests in `clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp`

You lost the check for `extern "C++" int main() {}` at global scope. To recap:

```c++
// These are disallowed by [basic.start.main]p3
//   The main function shall not be declared with a linkage-specification.
// We only want a pedantic warning for these
extern "C++" {
int main();
}
extern "C" {
int main();
}
// These are disallowed by [basic.start.main]p(3.4)
// We want a hard error
namespace X { extern "C" int main; }
extern "C" {
namespace Y {
  int main;
}
namespace Z {
  void main();
}
}
// These are allowed
namespace W {
  extern "C++" int main();
  extern "C" {
    extern "C++" {
      int main(void*);
    }
  }
}
```

(You should add a test for `extern "C" { namespace namespace_name { int main; } }` too)

Did you try doing it like https://github.com/llvm/llvm-project/issues/101512#issuecomment-2263650171 , checking `Decl->getLanguageLinkage()` rather than checking the DeclContext it's declared in?


https://github.com/llvm/llvm-project/pull/101853


More information about the cfe-commits mailing list