[PATCH] PING^2: Fix c++/22153

Josh Conner jconner@apple.com
Wed Oct 26 23:03:00 GMT 2005


Mark Mitchell wrote:
> Josh Conner wrote:
> 
> 
>>Thanks for looking at this.  Is the attached alternate an acceptable way
>>to discard the invalid declaration?  If so, I'll retest and resubmit.
> 
> 
> Upon further reflect, I think that particular spot is too big a hammer.
> 
> ...
> 
> The second error message is very helpful, and I'm afraid that your patch
> would make that go away.  (In fact, one could reasonably argue that the
> first error message should be omitted, and that we should issue only the
> second one.)

Hmm - I've been looking at a few different approaches to this, and the
one that makes the most sense to me based on your comments is to attempt
to parse the (invalid) member-function specialization as a
specialization instead of as a member function.  This approach seems to
be the most likely to match what the user was looking for, and has the
benefit of producing the most informative error message first.

So, if we're compiling this code (from g++.dg/parse/explicit1.C):

  struct foo {
    template<typename T> void bar (T &t) {}
    template<> void bar<double>(double &t) {}
  };

Whereas before we got these error messages:

  test4.C:3: error: invalid explicit specialization before '>' token
  test4.C:3: error: explicit specialization in non-namespace scope
'struct foo'
  test4.C:3: error: invalid member function declaration

We would now get:

  test4.C:3: error: explicit specialization in non-namespace scope
‘struct foo’
  test4.C:3: error: template-id ‘bar<double>’ for ‘void bar(double&)’
does not match any template declaration
  test4.C:3: error: invalid function declaration

Which seems reasonable to me.  This patch passes c and c++ on
arm-none-elf (3.4, 4.0, and mainline), and all default languages on
i686-pc-linux-gnu (mainline), except for the noted issue in explicit1.C.
 OK?

- Josh

2005-10-26  Josh Conner  <jconner@apple.com>

	PR c++/22153
	* parser.c (cp_parser_member_declaration): Detect and handle
	a template specialization.

2005-10-26  Josh Conner  <jconner@apple.com>

	PR c++/22153
	* g++.dg/template/crash38.C: New test.
	* g++.dg/parse/explicit1.C: Change expected errors.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr22153-4.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20051026/4b99df88/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: explicit1.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20051026/4b99df88/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: crash38.C
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20051026/4b99df88/attachment-0002.ksh>


More information about the Gcc-patches mailing list