"cannot declare %<::main%> to be %qs", "consteval");
if (!publicp)
error_at (location, "cannot declare %<::main%> to be static");
+ if (current_lang_depth () != 0)
+ pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
+ " linkage specification");
+ if (module_attach_p ())
+ error_at (location, "cannot attach %<::main%> to a named module");
inlinep = 0;
publicp = 1;
}
DECL_INTERFACE_KNOWN (decl) = 1;
if (DECL_NAME (decl)
- && MAIN_NAME_P (DECL_NAME (decl))
- && scope == global_namespace)
- error_at (DECL_SOURCE_LOCATION (decl),
- "cannot declare %<::main%> to be a global variable");
+ && MAIN_NAME_P (DECL_NAME (decl)))
+ {
+ if (scope == global_namespace)
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "cannot declare %<::main%> to be a global variable");
+ else if (DECL_EXTERN_C_P (decl))
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "an entity named %<main%> cannot be declared with "
+ "C language linkage");
+ }
/* Check that the variable can be safely declared as a concept.
Note that this also forbids explicit specializations. */
/* { dg-do compile } */
+/* { dg-additional-options "-Wno-error=pedantic" }
/* Check if entry points get implicit C linkage. If they don't, compiler will
* error on incompatible declarations */
int main();
-extern "C" int main();
+extern "C" int main(); // { dg-warning "linkage specification" }
#ifdef __MINGW32__
// { dg-module-do run }
// { dg-additional-options "-fmodules-ts -fcontracts -fcontract-continuation-mode=on" }
-module;
#include <cstdio>
-export module bar;
-// { dg-module-cmi bar }
import foo;
template<typename T>
bool bar_fn_pre(T n) { printf("bar fn pre(%d)\n", n); return true; }
-export
template<typename T>
T bar_fn(T n)
[[ pre: bar_fn_pre(n) && n > 0 ]]
// { dg-module-do run }
// { dg-additional-options "-fmodules-ts -fcontracts -fcontract-role=default:ignore,ignore,ignore" }
-module;
#include <cstdio>
-export module bar;
-// { dg-module-cmi bar }
import foo;
template<typename T>
bool bar_fn_pre(T n) { printf("bar fn pre(%d)\n", n); return true; }
-export
template<typename T>
T bar_fn(T n)
[[ pre: bar_fn_pre(n) && n > 0 ]]
// { dg-module-do run }
// { dg-additional-options "-fmodules-ts -fcontracts" }
-module;
#include <cstdio>
-export module baz;
import foo;
import bar;
export module foo;
// { dg-module-cmi foo }
+export
template<typename _Tp, _Tp __v>
struct integral_constant
{};
+export
template<bool __v>
using __bool_constant = integral_constant<bool, __v>;
+export
template<typename _Tp, typename... _Args>
struct __is_constructible_impl
: public __bool_constant<__is_constructible(_Tp, _Args...)>
// { dg-additional-options -fmodules-ts }
-module foo;
+import foo;
int main ()
{
--- /dev/null
+// { dg-additional-options "-fmodules-ts" }
+// { dg-prune-output "not writing module" }
+
+export module M;
+int main() {} // { dg-error "attach" }
--- /dev/null
+// { dg-do compile }
+// The main function shall not be declared with a linkage-specification.
+
+extern "C" {
+ int main(); // { dg-error "linkage" }
+}
+
+namespace foo {
+ extern "C" int main(); // { dg-error "linkage" }
+}
+
+extern "C++" int main(); // { dg-error "linkage" }
+
+extern "C" struct S { int main(); }; // OK
--- /dev/null
+// { dg-do compile }
+// A program that declares an entity named main with C language linkage
+// (in any namespace) is ill-formed.
+
+namespace foo {
+ extern "C" int main; // { dg-error "linkage" }
+ extern "C" struct A {
+ int main; // OK
+ };
+ extern "C" struct B {
+ int main(); // OK
+ };
+}