Bug 65750 - [4.9/5 Regression] misinterpret in a virtual member function with a C++11 style function signature
Summary: [4.9/5 Regression] misinterpret in a virtual member function with a C++11 sty...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.2
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 69139
  Show dependency treegraph
 
Reported: 2015-04-13 02:54 UTC by Usagi Ito
Modified: 2016-01-08 22:37 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.3
Known to fail:
Last reconfirmed: 2015-04-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Usagi Ito 2015-04-13 02:54:51 UTC
Repro:

#include <functional>

class a
{
  virtual auto f( std::function< void () > ) -> void;
  virtual auto g( std::function< auto () -> void > ) -> void;
};

auto main() -> int { }


Result 1 ( g++-5.0.0, 4.9.2 and >= 4.9.0 ):

prog.cc:6:16: error: implicit templates may not be 'virtual'
   virtual auto g( std::function< auto () -> void > ) -> void;

Result 2 ( g++-4.8.2, g++4.7.3 ):

(no errors, compile is succeed.)

Result 3 ( clang++-3.7.0, 3.6.0, 3.5.0 and 3.4 )

(no errors, compile is succeed.)
Comment 1 Jonathan Wakely 2015-04-13 09:21:40 UTC
Rejects-valid, introduced by support for C++14 return type deduction.


Reduced:

template<typename T> struct F { };

class a
{
  virtual auto f( F< void () > ) -> void;
  virtual auto g( F< auto () -> void > ) -> void;
};

auto main() -> int { }



The error in comment 0 is only on the 4.9 branch, 5.0 gives a different error:

s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
   virtual auto g( F< auto () -> void > ) -> void;
                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
s.cc:6:38: error: template argument 1 is invalid
   virtual auto g( F< auto () -> void > ) -> void;
                                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
   virtual auto g( F< auto () -> void > ) -> void;
                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
s.cc:6:38: error: template argument 1 is invalid
   virtual auto g( F< auto () -> void > ) -> void;
                                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
   virtual auto g( F< auto () -> void > ) -> void;
                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
s.cc:6:38: error: template argument 1 is invalid
   virtual auto g( F< auto () -> void > ) -> void;
                                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
   virtual auto g( F< auto () -> void > ) -> void;
                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
s.cc:6:38: error: template argument 1 is invalid
   virtual auto g( F< auto () -> void > ) -> void;
                                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
   virtual auto g( F< auto () -> void > ) -> void;
                      ^
s.cc:6:22: error: use of ‘auto’ in parameter declaration only available with -std=c++14 or -std=gnu++14
s.cc:6:38: error: template argument 1 is invalid
   virtual auto g( F< auto () -> void > ) -> void;
                                      ^
s.cc:6:19: error: ‘F’ is not a type
   virtual auto g( F< auto () -> void > ) -> void;
                   ^
s.cc:6:20: error: expected ‘,’ or ‘...’ before ‘<’ token
   virtual auto g( F< auto () -> void > ) -> void;
                    ^
Comment 2 Jason Merrill 2015-04-13 20:58:39 UTC
I think this is from the generic lambda/implicit template work rather than return type deduction.
Comment 3 Adam Butcher 2015-04-13 21:20:13 UTC
Agreed.  Upon seeing the 'auto' in the parameter list, we'll synthesize a template parameter for 'g'.  I think Paolo added the diagnostic for virtual to fix an ICE.

I'm not sure immediately how to handle this one.  For function pointer types "auto (" should have this behavior.  Maybe we need a bit of look-ahead to solve this (either for a function pointer or the trailing return arrow).

Looks like trying to tie down semantics at parse time is biting us again.
Comment 4 Jakub Jelinek 2015-04-14 09:17:39 UTC
It started to be rejected with r204714, and since r218879 there are lost of errors instead of just one warning and one error.
Comment 5 Adam Butcher 2015-04-14 21:03:26 UTC
This lookahead sketch (https://gcc.gnu.org/ml/gcc-patches/2015-04/msg00712.html) appears to work but I've don't limited testing.
Comment 6 Paolo Carlini 2015-05-22 15:29:27 UTC
Out of curiosity, what happened to the work linked in Comment #5? I see an Ok and then nothing more?
Comment 7 paolo@gcc.gnu.org 2015-06-24 15:11:37 UTC
Author: paolo
Date: Wed Jun 24 15:11:06 2015
New Revision: 224901

URL: https://gcc.gnu.org/viewcvs?rev=224901&root=gcc&view=rev
Log:
/cp
2015-06-24  Adam Butcher  <adam@jessamine.co.uk>

	PR c++/65750
	* parser.c (cp_parser_simple_type_specifier): Don't synthesize
	implicit template parm if 'auto' is a placeholder for trailing
	return type.

/testsuite
2015-06-24  Adam Butcher  <adam@jessamine.co.uk>

	PR c++/65750
	* g++.dg/cpp0x/trailing11.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/trailing11.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 Paolo Carlini 2015-06-24 15:13:00 UTC
Fixed in trunk so far.
Comment 9 paolo@gcc.gnu.org 2015-06-29 09:35:30 UTC
Author: paolo
Date: Mon Jun 29 09:34:58 2015
New Revision: 225114

URL: https://gcc.gnu.org/viewcvs?rev=225114&root=gcc&view=rev
Log:
/cp
2015-06-29  Adam Butcher  <adam@jessamine.co.uk>

	PR c++/65750
	* parser.c (cp_parser_simple_type_specifier): Don't synthesize
	implicit template parm if 'auto' is a placeholder for trailing
	return type.

/testsuite
2015-06-29  Adam Butcher  <adam@jessamine.co.uk>

	PR c++/65750
	* g++.dg/cpp0x/trailing11.C: New.

Added:
    branches/gcc-5-branch/gcc/testsuite/g++.dg/cpp0x/trailing11.C
Modified:
    branches/gcc-5-branch/gcc/cp/ChangeLog
    branches/gcc-5-branch/gcc/cp/parser.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 10 Paolo Carlini 2015-06-29 09:36:11 UTC
Fixed for 5.2 too.