In the following testcase, member i of Foo is not brought to scope by the using declaration, instead g++ reports: bellatrix:~/src/tests$ g++-3.4 -c using3.cpp -Wall using3.cpp: In member function `void Bar<T>::foo()': using3.cpp:11: error: `i' has not been declared this works with both 3.2 and 3.3 (in fact, they dont care if I omit the using declaration, too, but in whole this is a regression). template <class T> struct Foo { int i; }; template <class T> struct Bar : public Foo<T> { using Foo<T>::i; void foo() { i = 0; } }; int main() { Bar<int> bar; bar.foo(); return 0; } Release: [3.4 regression] g++-3.4 (GCC) 3.4 20030124 (experimental) Environment: ix86-linux
From: Paolo Carlini <pcarlini@unitus.it> To: gcc-gnats@gcc.gnu.org, rguenth@tat.physik.uni-tuebingen.de, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org Cc: Subject: Re: c++/9447: using Base<T>::member does not work Date: Mon, 27 Jan 2003 10:11:55 +0100 Seems a known issue (hopefully someone (Jason?) will deal with it soon!): http://gcc.gnu.org/ml/gcc-patches/2003-01/msg01560.html Paolo. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9447
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. Worked with 2.96
Still happens on the mainline (20030529).
*** Bug 11467 has been marked as a duplicate of this bug. ***
Subject: Bug 9447 CVSROOT: /cvs/gcc Module name: gcc Changes by: nathan@gcc.gnu.org 2003-07-29 11:16:50 Modified files: gcc/cp : ChangeLog decl.c decl2.c parser.c pt.c semantics.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: using1.C using2.C using3.C using4.C Log message: cp: PR c++/9447 * decl.c (add_binding): Add bval local variable. (push_class_level_binding): Likewise. Allow a USING_DECL to be pushed. * decl2.c (do_class_using_decl): The type of a using decl is unknown. * parser.c (cp_parser_postfix_expression): Refactor unqualified-id function call lookup code. * pt.c (tsubst): A USING_DECL will have unknown type. (tsubst_copy_and_build): Allow a using decl. (type_dependent_expression_p): A USING_DECL will make it dependent. * semantics.c (finish_member_declaration): Push a dependent using declaration. testsuite: PR c++/9447 * g++.dg/template/using1.C: New test. * g++.dg/template/using2.C: New test. * g++.dg/template/using3.C: New test. * g++.dg/template/using4.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3565&r2=1.3566 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1103&r2=1.1104 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.650&r2=1.651 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.91&r2=1.92 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.741&r2=1.742 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.338&r2=1.339 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2928&r2=1.2929 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/using1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/using2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/using3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/using4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
2003-07-29 Nathan Sidwell <nathan@codesourcery.com> PR c++/9447 * decl.c (add_binding): Add bval local variable. (push_class_level_binding): Likewise. Allow a USING_DECL to be pushed. * decl2.c (do_class_using_decl): The type of a using decl is unknown. * parser.c (cp_parser_postfix_expression): Refactor unqualified-id function call lookup code. * pt.c (tsubst): A USING_DECL will have unknown type. (tsubst_copy_and_build): Allow a using decl. (type_dependent_expression_p): A USING_DECL will make it dependent. * semantics.c (finish_member_declaration): Push a dependent using declaration.
Please reopen the bug. (Bugzilla didn't let me, since I'm not the reporter, just the reproter of a duplicate.) The original testcase is fixed, but the following doesn't work: ios:~/c/proba$ cat templ_base2.cc template <typename T> struct Base { T i; }; template <typename T> struct Derived : public Base<T> { using Base<T>::i; int get_i() { return i.f(); } }; ios:~/c/proba$ g++-cvs templ_base2.cc templ_base2.cc: In member function `int Derived<T>::get_i()': templ_base2.cc:8: error: insufficient contextual information to determine type zsh: exit 1 g++-cvs templ_base2.cc ios:~/c/proba$ g++-cvs -v Reading specs from /gml/shared/gcc-cvs/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs Configured with: ../gcc/configure --prefix=/gml/shared/gcc-cvs --enable-languages=c++ Thread model: posix gcc version 3.4 20030729 (experimental) ios:~/c/proba$
Still not fully fixed.
A similiar example with a different error message is: ---------------------------------------------------------- template <typename T> struct Base { T i; }; template <typename T> struct Derived : public Base<T> { using Base<T>::i; Derived() { i; } }; ---------------------------------------------------------- 9447.cc: In constructor `Derived<T>::Derived()': 9447.cc:8: error: statement cannot resolve address of overloaded function Regards, Volker
The new cases are accepted by icc 6.0 in strict mode (-Xc).
My second test case in bugreport 11467 doesn't really work: it passes the first parse, but fails when instantiated: hydra:~/c/proba$ cat templ_base3.cc template <typename T> struct Base { int i() { return 0; } }; template <typename T> struct Derived : public Base<T> { using Base<T>::i; int get_i(); { return i(); } }; int main() { Derived<int> a; return a.get_i(); } hydra:~/c/proba$ g++-cvs -v Reading specs from /gml/shared/gcc-cvs/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs Configured with: ../gcc/configure --prefix=/gml/shared/gcc-cvs --enable-languages=c++ Thread model: posix gcc version 3.4 20030731 (experimental) hydra:~/c/proba$ g++-cvs templ_base3.cc templ_base3.cc:8: error: expected unqualified-id zsh: exit 1 g++-cvs templ_base3.cc hydra:~/c/proba$
Created attachment 4535 [details] code snippet that fails to compile Hello, in fact there is syntax error in this code snippet line 8: int get_i(); { return i(); } ^ |------- If you remove the semicolon, the code should be compiled ok with the main branch CVS version (checked myself). Nevertheless this code snippet (borrowed from the gcc-bug mailing list, don't remember the exact msg number or mail-archive url): ---------------------------------------------- template <class T> struct B { int i; int f(); }; template <class T> struct D : public B<T> { void good(){ f(); } // no B<T>:: required void bad(){ i=0; } // does not compile with `head', void ugly(){ B<T>::i=0; } // ... this does. }; ------------------------------------------------ compiler rejected with the following diagnostics: t.cc: In member function `void D<T>::good()': t.cc:11: error: there are no arguments to `f' that depend on a template parameter, so a declaration of `f' must be available t.cc:11: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated) t.cc: In member function `void D<T>::bad()': t.cc:12: error: `i' undeclared (first use this function) t.cc:12: error: (Each undeclared identifier is reported only once for each function it appears in.) So you are quite right, it seems, that the problem is still exists. Best regards,
Subject: Bug 9447 CVSROOT: /cvs/gcc Module name: gcc Changes by: nathan@gcc.gnu.org 2003-08-01 09:01:12 Modified files: gcc/cp : ChangeLog decl2.c semantics.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: using5.C Log message: cp: PR c++/9447 * decl2.c (do_class_using_decl): Set type to NULL_TREE. * semantics.c (finish_expr_stmt): Do not convert to void in a template. testsuite: PR c++/9447 * g++.dg/template/using5.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3573&r2=1.3574 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.653&r2=1.654 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.339&r2=1.340 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2938&r2=1.2939 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/using5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
PR c++/9447 * decl2.c (do_class_using_decl): Set type to NULL_TREE. * semantics.c (finish_expr_stmt): Do not convert to void in a template.
The problem is still not fixed completely. Consider the following valid code: ------------------------------------------------------------------- template <typename> struct A { int i; }; template <typename T> struct B : public A<T> { using A<T>::i; int foo() const; }; struct C {}; template <typename T> int B<T>::foo() const { return i; } ------------------------------------------------------------------- Mainline still issues an error: bug.cc: In member function `int B<T>::foo() const': bug.cc:11: error: `i' undeclared (first use this function) bug.cc:11: error: (Each undeclared identifier is reported only once for each function it appears in.) Even stranger: If I remove the totally unrelated definition of struct C the code compiles! Nathan, could you please have another look? I really appreciate your efforts to make this work, since this bug prevents me from using mainline for my project.
2003-08-02 Nathan Sidwell <nathan@codesourcery.com> PR c++/9447 * cp-tree.def (USING_DECL): Document its type. * class.c (pushclass): If we're entering a template, push any dependent using decls it has. * decl2.c (do_class_using_decl): Refactor. Type is NULL iff it is a dependent scope. * pt.c (tsubst_decl) <USING_DECL case>: Set type. (tsubst): Remove USING_DECL checks. (type_dependent_expression_p): Remove USING_DECL case. * semantics.c (finish_member_declaration): A USING_DECL's type indicates whether it is dependent.
Subject: Bug 9447 CVSROOT: /cvs/gcc Module name: gcc Changes by: nathan@gcc.gnu.org 2003-08-02 18:52:16 Modified files: gcc/cp : ChangeLog class.c cp-tree.def decl.c decl2.c pt.c semantics.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: using7.C Log message: cp: PR c++/9447 * cp-tree.def (USING_DECL): Document its type. * class.c (pushclass): If we're entering a template, push any dependent using decls it has. * decl2.c (do_class_using_decl): Refactor. Type is NULL iff it is a dependent scope. * pt.c (tsubst_decl) <USING_DECL case>: Set type. (tsubst): Remove USING_DECL checks. (type_dependent_expression_p): Remove USING_DECL case. * semantics.c (finish_member_declaration): A USING_DECL's type indicates whether it is dependent. testsuite: PR c++/9447 * g++.dg/template/using7.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3582&r2=1.3583 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.561&r2=1.562 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.def.diff?cvsroot=gcc&r1=1.77&r2=1.78 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1107&r2=1.1108 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.655&r2=1.656 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.750&r2=1.751 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.343&r2=1.344 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2947&r2=1.2948 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/using7.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Now all my real life test cases are working, thank you very much!!!!