This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH: PR 11493 and PR 11495
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Gerald Pfeifer <gerald at pfeifer dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: 16 Jul 2003 10:02:41 -0700
- Subject: Re: C++ PATCH: PR 11493 and PR 11495
- Organization: CodeSourcery, LLC
- References: <Pine.BSF.4.56.0307161413580.31872@naos.dbai.tuwien.ac.at>
On Wed, 2003-07-16 at 05:55, Gerald Pfeifer wrote:
> (First, late me state that I really appreciate the huge number of fixes
> and improvements you've recently made!)
>
> Unfortunately, I found the current failure mode for this patch not to be
> sufficiently helpful:
>
> template <class T>
> struct D : T {
> void dosomething();
> };
>
> template <class T>
> void D<T>::dosomething() {
> f(); // problem
> this->g(); // fix variant 1
> T::h(); // fix variant 2
> }
>
> x.cc: In member function `void D<T>::dosomething()':
> x.cc:8: error: there are no arguments to `f' that depend on a template
> parameter, so a declaration of `f' must be available
> x.cc:8: error: (if you use `-fpermissive', G++ will accept your code, but
> allowing the use of an undeclared name is deprecated)
>
> Without following gcc-patches and your changes to libstdc++, I certainly
> would not have known that I need to add "this->" to qualify such
> functions.
FWIW, the EDG front end, when running in it's strict mode, just says:
"test.C", line 8: error: identifier "f" is undefined
The rules for name lookup in templates are pretty arcane. Knowing when
you need to say "this->" or "typename" is tricky.
One reason I didn't suggest the "this->" trick in the message was that
it may not be the right answer. If the function is static,
that will work -- but many people would prefer to write "D<T>::f()".
Also, the user might be trying to call a namespace-scope function. For
example, V3 had erroneous code like this:
template <typename T>
void D<T>::f(const char* s1, T t) { strlen (s1); }
Here, the solution is "#include <cstring>".
> Alos, I'm not a language lawyer, but is "this->g()" indeed a declaration??
No -- but the use of "this->" postpones lookup because the type of
"this" is dependent on a template parameter.
> I'm a bit afraid I may start sounding like Joseph, but for changes like
> this, which surely will break tons of C++ programs out there, we really
> need to provide more information for our users, for example by providing
> a clear explanation as part of the documentation for -fpermissive and as
> part of the release notes.
>
> Most importantly, this should include how to rewrite programs affected
> by this.
Do you think the bits that Wolfgang pointed at our sufficient? Do you
have ideas about how to make them more accessible to people?
Thanks,
--
Mark Mitchell <mark@codesourcery.com>
CodeSourcery, LLC