From e74a506f4eec90fc1d4839f8cde506be8f99c9de Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 12 Oct 2012 14:38:11 +0000 Subject: [PATCH] re PR c++/24449 (Unable to declare friend main() from class template) /cp 2012-10-12 Paolo Carlini PR c++/24449 * decl.c (grokfndecl): When checking for ::main declarations use PROCESSING_REAL_TEMPLATE_DECL_P(). /testsuite 2012-10-12 Paolo Carlini PR c++/24449 * g++.dg/parse/friend-main.C: New. From-SVN: r192402 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/decl.c | 2 +- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/parse/friend-main.C | 30 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/friend-main.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ad765412832..6730b109378 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-10-12 Paolo Carlini + + PR c++/24449 + * decl.c (grokfndecl): When checking for ::main declarations + use PROCESSING_REAL_TEMPLATE_DECL_P(). + 2012-10-12 Marc Glisse PR c++/53055 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f97f7b193a0..468343f40a3 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7416,7 +7416,7 @@ grokfndecl (tree ctype, if (ctype == NULL_TREE && DECL_MAIN_P (decl)) { - if (processing_template_decl) + if (PROCESSING_REAL_TEMPLATE_DECL_P()) error ("cannot declare %<::main%> to be a template"); if (inlinep) error ("cannot declare %<::main%> to be inline"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3b9f121baea..862b4273055 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-10-12 Paolo Carlini + + PR c++/24449 + * g++.dg/parse/friend-main.C: New. + 2012-10-12 Marc Glisse PR c++/53055 diff --git a/gcc/testsuite/g++.dg/parse/friend-main.C b/gcc/testsuite/g++.dg/parse/friend-main.C new file mode 100644 index 00000000000..e6d32e71ba4 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/friend-main.C @@ -0,0 +1,30 @@ +// PR c++/24449 + +class Fooa +{ + friend int main(); +}; + +template class Foob +{ + friend int main(); + int i; +}; + +int main() +{ + Foob a; + a.i = 7; +} + +class Fooc +{ + template friend int main(); // { dg-error "cannot declare .::main. to be a template" } +}; + +template class Food +{ + template friend int main(); // { dg-error "cannot declare .::main. to be a template" } +}; + +template int main() {} // { dg-error "cannot declare .::main. to be a template" }