Hi, First of all this is my first bug report to GNU GCC so please bare with me. The issue I having is with typedef assisted declarations of class/struct member functions. It seems to me that cv-qualifiers on function typedef's are treated inconsistantly depending on the scope of the typedef. The below code demonstrates the problem: with NS_SCOPE defined the code compiles fine with "-Wall -Wextra -pedantic" on 4.3.2 but when NS_SCOPE is undefined, the const qualifier is ignored with "error: ignoring ‘const’ qualifiers added to function type". To me this seems completely inconsistent and there is no explaination as to why the qualifer is ignored. ---snip--- #include <iostream> #ifdef NS_SCOPE typedef void (function_type)(int) const; #endif template <typename T> struct S1 { #ifndef NS_SCOPE typedef void (function_type)(int) const; #endif }; struct S2: public S1<int> { virtual function_type f = 0; }; struct S3: public S2 { void f (int i) const { std::cout << "Hello world: " << i << std::endl; } }; int main() { S3 s; s.f(5); } ---snip--- I did find a C++ defect report that may be relevent, but to be honest, i'm not certain what is going on with regard to the standard here http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#295 I hope this can be resolved because it will allow for some really groovy template generated interfaces. Visual Studio 2005 (the only other compiler I have to hand) seems to compile this code without NS_SCOPE defined, but I'm uncertain how to thoroughly test this there.
EDG accepts the code. With GCC 4.3 and newer we reject the code with t.C: In function ‘int main()’: t.C:32: error: cannot declare variable ‘s’ to be of abstract type ‘S3’ t.C:21: note: because the following virtual functions are pure within ‘S3’: t.C:16: note: virtual void S2::f(int) GCC 4.2 has this in addition to the CV error. Of course the reason is the same. GCC never accepted the code, so this is not a regression.
Related to PR 29993 where we rejected this code before because of the const. I want to say that even though we handle them now, we don't handle them fully now.
My patch for 39310 also fixes this bug.
*** Bug 39321 has been marked as a duplicate of this bug. ***
Subject: Bug 37806 Author: jason Date: Tue Mar 31 18:31:17 2009 New Revision: 145365 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145365 Log: PR c++/37806 * typeck.c (cp_apply_type_quals_to_decl): Don't apply any quals to a typedef. * tree.c (cp_build_qualified_type_real): Don't apply restrict to a function type. * decl.h (enum decl_context): Add TEMPLATE_TYPE_ARG. * decl.c (groktypename): Add is_template_arg parameter. (grokdeclarator): Allow function cv-quals on a template type arg. * parser.c (cp_parser_new_type_id, cp_parser_type_id): Add is_template_arg argument in calls to groktypename. * cp-tree.h: Adjust prototype. * error.c (dump_type_prefix, dump_type_suffix): Fix plain FUNCTION_TYPE printing. PR libstdc++/39310 * include/tr1_impl/type_traits (is_function): Add partial specializations with function cv-quals. (__is_function_helper): Remove. (is_member_pointer): Don't define in terms of is_member_*_pointer. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/decl.c trunk/gcc/cp/decl.h trunk/gcc/cp/error.c trunk/gcc/cp/parser.c trunk/gcc/cp/tree.c trunk/gcc/cp/typeck.c trunk/gcc/testsuite/g++.dg/template/qualttp20.C trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/tr1_impl/type_traits
Subject: Bug 37806 Author: jason Date: Tue Mar 31 18:37:49 2009 New Revision: 145366 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145366 Log: PR c++/37806 * g++.dg/template/typedef17.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/typedef17.C Modified: trunk/gcc/testsuite/ChangeLog
Subject: Bug 37806 Author: jason Date: Tue Apr 7 04:38:10 2009 New Revision: 145648 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145648 Log: * decl.c (grokdeclarator): Reject pointer to qualified function type. PR c++/37806, core issue 547 * typeck.c (cp_apply_type_quals_to_decl): Don't apply any quals to a typedef. * tree.c (cp_build_qualified_type_real): Don't apply restrict to a function type. * decl.h (enum decl_context): Add TEMPLATE_TYPE_ARG. * decl.c (groktypename): Add is_template_arg parameter. (grokdeclarator): Allow function cv-quals on a template type arg. * parser.c (cp_parser_new_type_id, cp_parser_type_id): Add is_template_arg argument in calls to groktypename. * cp-tree.h: Adjust prototype. * error.c (dump_type_prefix, dump_type_suffix): Fix plain FUNCTION_TYPE printing. PR libstdc++/39310 * include/tr1_impl/type_traits (is_function): Add partial specializations with function cv-quals. (__is_function_helper): Remove. (is_member_pointer): Don't define in terms of is_member_*_pointer. Added: branches/gcc-4_4-branch/gcc/testsuite/g++.dg/other/typedef2.C - copied unchanged from r145367, trunk/gcc/testsuite/g++.dg/other/typedef2.C branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/typedef17.C - copied unchanged from r145367, trunk/gcc/testsuite/g++.dg/template/typedef17.C Modified: branches/gcc-4_4-branch/gcc/cp/ChangeLog branches/gcc-4_4-branch/gcc/cp/cp-tree.h branches/gcc-4_4-branch/gcc/cp/decl.c branches/gcc-4_4-branch/gcc/cp/decl.h branches/gcc-4_4-branch/gcc/cp/error.c branches/gcc-4_4-branch/gcc/cp/parser.c branches/gcc-4_4-branch/gcc/cp/tree.c branches/gcc-4_4-branch/gcc/cp/typeck.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/qualttp20.C branches/gcc-4_4-branch/libstdc++-v3/ChangeLog branches/gcc-4_4-branch/libstdc++-v3/include/tr1_impl/type_traits
Fixed for 4.4.