From b63b6ee9a00ef0710d899df6cfda78a1b8bd762a Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 22 Jan 2014 01:43:19 +0000 Subject: Enforce restrictions that 'main' is not allowed to be deleted, or to be used by the program, in C++. (We allow the latter as an extension, since we've always permitted it, and GCC does the same, and our supported C++ ABIs don't do anything special in main.) llvm-svn: 199782 --- clang/lib/Sema/SemaExpr.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3640c5ad24b..ff54b6b24e4 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -264,13 +264,18 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, SmallVectorImpl &Suppressed = Pos->second; for (unsigned I = 0, N = Suppressed.size(); I != N; ++I) Diag(Suppressed[I].first, Suppressed[I].second); - + // Clear out the list of suppressed diagnostics, so that we don't emit // them again for this specialization. However, we don't obsolete this // entry from the table, because we want to avoid ever emitting these // diagnostics again. Suppressed.clear(); } + + // C++ [basic.start.main]p3: + // The function 'main' shall not be used within a program. + if (cast(D)->isMain()) + Diag(Loc, diag::ext_main_used); } // See if this is an auto-typed variable whose initializer we are parsing. -- cgit v1.2.3