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

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 02:56:21 PDT 2024


================
@@ -12370,6 +12379,17 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
   }
 }
 
+bool Sema::CheckLinkageSpecification(DeclContext *DC, Decl *D) {
+  // [basic.start.main] p2
+  //   The main function shall not be declared with a linkage-specification.
+  if (DC->isExternCContext()) {
+    Diag(D->getLocation(), diag::err_main_invalid_linkage_specification);
+    D->setInvalidDecl();
+    return true;
+  }
+  return false;
+}
----------------
Sirraide wrote:

Currently, it’s only used in one place (the use where we check variable declarations should not be there I think), so I’d just inline it.

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


More information about the cfe-commits mailing list